Promised

Convert back and forth from javascript Promises to Callbacks

Promised #.

Convert back and forth from javascript Promises to Callbacks

This library works on both node and browser.
Currently it supports jQuery and Q promises.

Usage

varP=require('promised')// or window.promised in browsersvarpromisedQ=P.Q(Q)// Use Promised with Q deferredsvarpromisedJ=P.$(jQuery)// Use Promised with JQuery deferreds// Or you can give P two functions://// deferrer: takes a single argument and creates a deferred object// with it or returns it if already a referred.//// promiser: takes a deferred object and returns a promise for it//varpromisedCustom=P(defferer,promiser)

API

In the following signatures callback<e,s> means a function that
takes two arguments, one for error and the second for success. And
callback<v> is a function that takes a single value; in node
API these kind of callbacks are used for predicates, functions that
either invoke the callback with true or false, that's why each of
the following functions has a p. version which works with this
kind of predicate callbacks.

Deferred generator to Callback receiver

P(function, receiver, args...) -> function(args..., callback<e,s>)

P.p(function, receiver, args...) -> function(args..., callback<v>)

This transformation takes a function that will return a deferred and
will transform it into a function that expects any number of arguments
and a callback as the last one.

Turn a Deferred into a Function (callback) that resolves/rejects

If p.set is given multiple deferred_s each of them will be resolved
to the corresponding argument the _callback is called with.
If .set is given multiple _deferred_s all of them will be
resolved/rejected to the same value.