4 ms·
> In order to maximize your usage of this feature, you'll want to use modules from the ecosystem that expose Promise instead of just a callback. Bluebird which
by inglor 10y ago
> In order to maximize your usage of this feature, you'll want to use modules from the ecosystem that expose Promise instead of just a callback.
Bluebird which is one of the most popular promise libraries converts entire callback APIs to promises in one go:
Promise.promisifyAll(require("fs")); // fs is now promisified and methods return promises.
(full disclosure, I'm a bluebird contributor)
- Touche 10y agoCan I import promisifyAll without bringing all of Bluebird?
- inglor 10y agopromisifyAll is _blazing_ fast because it does this: https://github.com/petkaantonov/bluebird/blob/master/src/promisify.js https://github.com/petkaantonov/bluebird/blob/master/src/pro... It builds a function dynamically and then compiles it and lets the JIT optimize it - it incurs very little overhead. This is impossible if your only tool is the promise constructor. That said - there are packages that do this without bluebird - like thenify. Also note - you can use bluebird for promisification and native promises for other stuff if you'd like and it'd work seamlessly as bluebird passes the Promises/A+ test suite.
- Touche 10y agoIs that a no? Do you have any data that shows Promise speed to be a blocker on UI performance?
- phpnode 10y agoBluebird is mainly designed for node (V8) and promise performance can make a massive difference on the server. On the client there tend to be fewer async calls and so promise performance is usually less of a factor, but obviously, it depends what you're doing.
- Touche 10y ago> promise performance can make a massive difference on the server. Great, got data on the type of difference?
- phpnode 10y agoCheck out the Bluebird benchmarks [0], or you can easily try it for yourself - create a simple web server which does some makework async task, like stating a bunch of files, then benchmark with ab or something better. [0] https://github.com/petkaantonov/bluebird/blob/master/docs/docs/benchmarks.md https://github.com/petkaantonov/bluebird/blob/master/docs/do...
- Touche 10y agoWhy should I do the work, you made the claim?
- phpnode 10y agoBy the same token, why do I owe you any further evidence?
- Touche 10y agoYou haven't provided any evidence so far. You owe evidence because you made a claim. If you are unsure whether Bluebird's Promise performance makes a difference in a real-world scenario, why make such a claim?
- phpnode 10y agoYou are asking a question, I do not owe you an answer, it's up to you to find out whether this stuff matters for your use case. I've done these tests myself, it is trivial for you to do the same. Do your own homework.
- BinaryIdiot 10y ago> promisifyAll is _blazing_ fast I'm not sure I'd necessarily call ```promisifyAll()``` "blazing fast" but in all fairness it's a cost incurred up front and that's it so it's not that bad.
- phpnode 10y agoThe call itself is relatively expensive, but as you say it's a one off call at startup time and the methods it produces are faster than explicit promisification using `new Promise`, they are blazing fast :)
- xpaulbettsx 10y agoCheck out github.com/sindresorhus/pify