3 ms·
Promises aren't just about keeping things flat. The biggest value to me is being able to avoid the passing around of callbacks and them relying on varying conv
by phleet 13y ago
Promises aren't just about keeping things flat.
The biggest value to me is being able to avoid the passing around of callbacks and them relying on varying conventions (some async are function(args, ..., callback(err, data)), some are function(args, ..., callback(data), errback(err)), some are function({success: callback, error: errback})).
Promises solve this problem by not passing around callbacks _at all_. Instead you return the promise and let the consumer attach the callback itself. And once we have promises widely available and part of the standard library, the calling conventions will be standardized too.
EDIT: I agree that as it stands, the lack of standardization of promises (jQuery's are mutable, for instance) is a pain, and that documentation could certainly be better.
- nailer 13y agoI can install pretty much anything from npm at this point and put money on it being a single callback, err first.