You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
821 B

4 years ago
  1. # call-me-maybe [![Build Status](https://travis-ci.org/limulus/call-me-maybe.svg?branch=master)](https://travis-ci.org/limulus/call-me-maybe)
  2. Let your JS API users either give you a callback or receive a promise.
  3. ## Usage
  4. ```javascript
  5. var maybe = require("call-me-maybe")
  6. module.exports = function asyncFunc (cb) {
  7. return maybe(cb, new Promise(function(resolve, reject) {
  8. // ...
  9. }))
  10. }
  11. ```
  12. ## API
  13. ### maybe(cb, promise)
  14. 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:
  15. - If `promise` is fulfilled, then it is called with the result of the promise: `cb(null, result)`
  16. - If `promise` is rejected, then it is called with the rejection error: `cb(err)`
  17. If `cb` is falsey, then `promise` is retuned.