一个基本但性能良好的 Promise 实现。
lie 是一款小巧、高性能的 Promise 库,实现了 Promises/A+ 规范 (1.1 版)。 最初是 Ruben Verborgh 的 promiscuous 的分支,在 2.6 版本中,它成为 Chris Burgmer 根据 ayepromise 所做的分支。
npm install lie
var Promise = require('lie');
// or use the pollyfill
require('lie/polyfill');您可以使用 browserify (推荐) 或从 dist 文件夹中获取其中一个文件:
实现了 ES6 API 标准: ```js new Promise(function(resolve, reject){ doSomething(function(err, result) { if (err) { reject(err); } else { resolve(result); } }); }).then(function (value) { //on success }, function (reason) { //on error }).catch(function (reason) { //shortcut for error handling });
Promise.all([ //array of promises or values ]).then(function ([/* array of results */]));
Promise.race([
//array of promises or values
]);
// either resolves or rejects depending on the first value to do so
``` 在 Node.js 中,当拒绝的 Promise 没有被捕获时,lie 会发出 unhandledRejection 事件,这符合 io.js 的做法如何实现。这使得它可以在 Node.js 和浏览器中都充当 Promise 的代理。
暂无开放 Issues,或尚未同步最近议题。