maybe.js 330 B

123456789101112131415161718
  1. "use strict"
  2. var next = require('./next.js')
  3. module.exports = function maybe (cb, promise) {
  4. if (cb) {
  5. promise
  6. .then(function (result) {
  7. next(function () { cb(null, result) })
  8. }, function (err) {
  9. next(function () { cb(err) })
  10. })
  11. return undefined
  12. }
  13. else {
  14. return promise
  15. }
  16. }