Skip to content
Eugene Lazutkin edited this page Mar 19, 2016 · 3 revisions

A function that adapts any value to a promise. It detects foreign promises (then()-ables) and adapt to them correctly. As a result it returns a promise: either then()-able, or a resolved promise of a given type.

It takes up to two arguments:

  • value — a value to adapt.
  • Deferred — an optional constructor of deferred (realistically Deferred or FastDeferred), or a falsy value to use the standard Promise.

Example:

var when = require('heya-async/when');

when(3).then(function (value) {
  console.log('Is it 3? Yes:', value); return value;
});

Clone this wiki locally