* Wraps a function that expects a node-style callback as its final * argument. This callback expects two arguments: an error value (which will be * null if the call succeeded), and the success value as the second argument. * The callback will the resolve or reject the returned promise, based on i
(fn, ...args)
| 47 | * result of the provided function's callback. |
| 48 | */ |
| 49 | function checkedNodeCall(fn, ...args) { |
| 50 | return new Promise(function (fulfill, reject) { |
| 51 | try { |
| 52 | fn(...args, function (error, value) { |
| 53 | error ? reject(error) : fulfill(value) |
| 54 | }) |
| 55 | } catch (ex) { |
| 56 | reject(ex) |
| 57 | } |
| 58 | }) |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Registers a listener to invoke when a promise is resolved, regardless |