项目作者: Volune

项目描述 :
An operator that converts asynchronous functions expecting a callback to functions returning a Promise. ### promise = asyncFunc[Ψ]()
高级语言: JavaScript
项目地址: git://github.com/Volune/callback-to-promise-operator.git
创建时间: 2017-02-04T15:21:02Z
项目社区:https://github.com/Volune/callback-to-promise-operator

开源协议:MIT License

下载


Callback-To-Promise Operator

npm version Build Status

An operator that converts asynchronous functions expecting a callback to functions returning a Promise.

Example

  1. // Use whatever variable name that you like for the operator
  2. const $P = require('callback-to-promise-operator').default;
  3. // With an asynchronous function expection a callback
  4. const delayUpperCase = (value, callback) => {
  5. setTimeout(() => callback(null, value.toUpperCase()), 1000);
  6. };
  7. // Use it as if it was returning a Promise
  8. delayUpperCase[$P]('string')
  9. .then((result) => {
  10. console.log(result);
  11. });