blob: b3c5d44b22eefea43859f81b3b73b79bce63730e [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001"use strict"
2
3var next = (global.process && process.nextTick) || global.setImmediate || function (f) {
4 setTimeout(f, 0)
5}
6
7module.exports = function maybe (cb, promise) {
8 if (cb) {
9 promise
10 .then(function (result) {
11 next(function () { cb(null, result) })
12 }, function (err) {
13 next(function () { cb(err) })
14 })
15 return undefined
16 }
17 else {
18 return promise
19 }
20}