Decouple $q in AngularJS 2.0 (and/or switch to bluebird) #6697
Description
AngularJS currently uses a shim of q. I haven't dug into the actual implementation, but I think it might be interesting to review a possible change for the 2.0 milestone.
I think AngularJS should use an agnostic $Promise
service accross the framework, and extract the current $q
shim out of the core. Letting user choose their Promise framework. Thanks to the unified promise spec, this should be doable.
Also, I would strongly advise to pick bluebird over q for the future.
I've been doing NodeJS work for a couple of years, and switching from q to the very well-crafted bluebird has been a really pleasant experience. The API is far superior and the performance is unmatched.
Regarding performance, have a look at this article.
But you said promises are slow!
Yes, I know I wrote that. But I was wrong. A month after I wrote the giant comparison of async patterns, Petka Antonov wrote Bluebird. Its a wicked fast promise library, and here are the charts to prove it.
file | time(ms) | memory(MB) |
---|---|---|
callbacks-original.js | 316 | 34.97 |
callbacks-flattened.js | 335 | 35.10 |
callbacks-catcher.js | 355 | 30.20 |
promises-bluebird-generator.js | 364 | 41.89 |
dst-streamline.js | 441 | 46.91 |
callbacks-deferred-queue.js | 455 | 38.10 |
callbacks-generator-suspend.js | 466 | 45.20 |
promises-bluebird.js | 512 | 57.45 |
thunks-generator-gens.js | 517 | 40.29 |
thunks-generator-co.js | 707 | 47.95 |
promises-compose-bluebird.js | 710 | 73.11 |
callbacks-generator-genny.js | 801 | 67.67 |
callbacks-async-waterfall.js | 989 | 89.97 |
promises-bluebird-spawn.js | 1227 | 66.98 |
promises-kew.js | 1578 | 105.14 |
dst-stratifiedjs-compiled.js | 2341 | 148.24 |
rx.js | 2369 | 266.59 |
promises-when.js | 7950 | 240.11 |
promises-q-generator.js | 21828 | 702.93 |
promises-q.js | 28262 | 712.93 |