call-me-maybe
Let your JS API users either give you a callback or receive a promise
Last updated 5 years ago by limulus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install call-me-maybe 
SYNC missed versions from official npm registry.

call-me-maybe Build Status

Let your JS API users either give you a callback or receive a promise.

Usage

var maybe = require("call-me-maybe")

module.exports = function asyncFunc (cb) {
  return maybe(cb, new Promise(function(resolve, reject) {
    // ...
  }))
}

API

maybe(cb, promise)

If the callback cb is truthy, returns undefined and will call cb when promise is settled. The parameters passed to cb are standard error-first:

  • If promise is fulfilled, then it is called with the result of the promise: cb(null, result)
  • If promise is rejected, then it is called with the rejection error: cb(err)

If cb is falsey, then promise is retuned.

Current Tags

  • 1.0.1                                ...           latest (5 years ago)

2 Versions

  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 8,796
This Week 49,095
This Month 525,762
Last Day 19,405
Last Week 133,563
Last Month 508,906
Dependencies (0)
None
Dev Dependencies (3)
Dependents (133)

Copyright 2014 - 2016 © taobao.org |