cujojs / when

A solid, fast Promises/A+ and when() implementation, plus other async goodies.
Other
3.44k stars 396 forks source link

Add better callbacks.call example #461

Closed briancavalier closed 9 years ago

briancavalier commented 9 years ago

Fix #460

unscriptable commented 9 years ago

:+1:

ChrisEineke commented 9 years ago

So, does callbacks.call require the last two arguments exactly to be the node-style callbacks? Or is one enough?

briancavalier commented 9 years ago

@ceineke The last two arguments should be "normal" callbacks (i.e. each accepts a single parameter), rather than node-style callbacks. They work like the resolve and reject parameters passed in the ES6 Promise constructor.

Yes, using a single callback is enough--you can ignore the reject parameter if you don't need it, just like you can ignore it when using an ES6 Promise constructor or when.promise. For example, these two are equivalent:

// Declare both resolve and reject as parameters
callbacks.call((x, y, z, resolve, reject) => resolve(x+y+z), 10, 20, 30); // promise for 60

// Don't declare reject because it isn't needed
callbacks.call((x, y, z, resolve) => resolve(x+y+z), 10, 20, 30); // promise for 60

Make sense?

ChrisEineke commented 9 years ago

Gotcha. :) :+1: