MCPcopy
hub / github.com/cujojs/when / bindCallback

Function bindCallback

node.js:230–248  ·  view source on GitHub ↗

* Attaches a node-style callback to a promise, ensuring the callback is * called for either fulfillment or rejection. Returns a promise with the same * state as the passed-in promise. * * @example * var deferred = when.defer(); * * function callback(err, value) { * // Handle err or

(promise, callback)

Source from the content-addressed store, hash-verified

228 * @returns {Promise} A promise with the same state as the passed-in promise.
229 */
230 function bindCallback(promise, callback) {
231 promise = when(promise);
232
233 if (callback) {
234 promise.then(success, wrapped);
235 }
236
237 return promise;
238
239 function success(value) {
240 wrapped(null, value);
241 }
242
243 function wrapped(err, value) {
244 setTimer(function () {
245 callback(err, value);
246 }, 0);
247 }
248 }
249
250 /**
251 * Takes a node-style callback and returns new function that accepts a

Callers 1

liftCallbackFunction · 0.85

Calls 1

whenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…