Skip to content
Let your JS API users either give you a callback or receive a promise
Branch: master
Clone or download
Latest commit 6c25a1d Mar 27, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Fix test to avoid race condition induced failures Sep 12, 2015
.gitignore Initial commit Sep 11, 2015
.travis.yml Travis CI config Sep 12, 2015
.zuul.yml zuul config Sep 12, 2015
LICENSE Initial commit Sep 11, 2015
README.md Fix typo in README.md Mar 24, 2017
index.js IE8 doesn't like "catch" as an identifier Sep 12, 2015
package.json 1.0.1 Sep 12, 2015

README.md

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 returned.

You can’t perform that action at this time.