index.js 408 B

1234567891011121314151617181920
  1. "use strict"
  2. var next = (global.process && process.nextTick) || global.setImmediate || function (f) {
  3. setTimeout(f, 0)
  4. }
  5. module.exports = function maybe (cb, promise) {
  6. if (cb) {
  7. promise
  8. .then(function (result) {
  9. next(function () { cb(null, result) })
  10. }, function (err) {
  11. next(function () { cb(err) })
  12. })
  13. return undefined
  14. }
  15. else {
  16. return promise
  17. }
  18. }