Reputation: 633
I am using a node module & instead of using PromisifyAll() I am creating a new promise object each time when I am invoking a method of that module.
This is a safe way to promisify?
If not then my entire code structure will change. So is it very critical to change or as long as I am using Promise its fine.
Also is there an impact on Memory or CPU if I promisify each method individually?
Upvotes: 4
Views: 1110
Reputation: 276306
I think I'm in a unique position to answer this as both Bluebird and NodeJS core.
It is a safe but relatively slow method of doing promisify (using new Promise
), if you are not creating multiple requests per promise then you should be fine with it. If your number of promises scales with your number of requests then it starts to matter.
You can see benchmarks from last week (with new Promise
) here: https://kyrylkov.com/2017/04/25/native-promises-async-functions-nodejs-8-performance/
Bluebird does a lot of clever things in promisify
and promisifyAll
that make it fast.
Note, I've proposed util.promisify
for Node and we're working on adding it to the core.
Upvotes: 4