cujojs/when — pull request #215 by phated (2013-10-29 09:49:54+00:00)
Title: Add createDeferred method in node/function

This is used for creating a deferred object that call nodeback on resolve or reject.

Q has something like this called nodeify (https://github.com/kriskowal/q/wiki/API-Reference#promisenodeifycallback) and a library called nodeify (https://github.com/then/nodeify).

Stripe API is using When internally, but they had to create this utility themselves (https://github.com/stripe/stripe-node/blob/master/lib/StripeResource.js#L67-L81).

With the prevalence of libraries moving towards the a dual-promise/callback style, I think a method like this would alleviate libraries creating this utility function internally.

Basic tests are included and can probably be expanded on.

In all three libraries mentioned, they are using nextTick or setTimeout to move the callback out of the promise stack. I think @domenic or @kriskowal would probably be able to explain why this is done.