微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

node-promise

程序名称:node-promise

授权协议: MIT

操作系统: 跨平台

开发语言: JavaScript

node-promise 介绍

node-promise 在 Node.js 平台上提供了完整的 Promises
的实现。

The node-promise module features a promise implementation with:

  • Chainable promises
  • Promises throw errors if an error handler is not provided
  • Commonjs promise proposal [1] compliant
  • Immutable once fulfilled to reduce possible side-effects
  • Promises can be used securely (as separate resolver/promise pairs in ocap situations)
  • Backwards compatibility where possible (addCallback, addErrback, emitSuccess, and emitError should still behave as expected)

Utility functions, including:

  • when() - normalization of sync (normal values) and async (promises)
  • all() - Create a promise that accumulate multiple concurrent promises
  • first() - Find the first promise to be fulfilled in a group of promises
  • seq() - Sequentially execute a set of promise returning functions
  • delay() - Returns a promise that is fulfilled after a given amount of time
  • execute() - Executes a function that takes a callback and returns a promise (thank you Benjamin Thomas for providing this)

示例代码

var Promise = require("promise").Promise;
var promise = new Promise();
asyncoperation(function(){
  Promise.resolve("succesful result");
});
promise -> given to the consumer

node-promise 官网

https://github.com/kriszyp/node-promise

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐