call-me-maybe
Let your JS API users either give you a callback or receive a promise
Last updated 2 years ago by limulus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm 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.2-beta.1                                ...           beta (2 years ago)
  • 1.0.2                                ...           latest (2 years ago)
  • 1.0.2                                ...           next (2 years ago)

4 Versions

  • 1.0.2                                ...           2 years ago
  • 1.0.2-beta.1                                ...           2 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (12)

Copyright 2013 - present © cnpmjs.org | Home |