Answer the question
In order to leave comments, you need to log in
How to use Bluebird?
1. What is the advantage of Bluebird over Promise?
2. How does promisifyAll determine which features to promisify? Does it override All functions? Does it do the same with nested exports? What happens to synchronous functions like fs.readFileSync?
3. How to use promisifyAll in TypeScript?
4. Are there better alternatives for promissification? For example, a promisified version of the node.js standard libraries
Answer the question
In order to leave comments, you need to log in
1. Very simple
2. promisify takes a `fn` function and returns a function that internally returns a promise, which internally calls `fn` with `arguments` + a function that receives another `arguments` and looks if arguments[0] ( err) is not null, then reject the promise with this err, otherwise resolve the promise with the arguments.
It looks like this:
const promisify = fn => (...args) => new Promise((resolve, reject) => {
fn(...args, (err, ...nextargs) => {
if (err) return reject(err)
return resolve(...nextargs)
})
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question