util.promisify converts callback-based functions to Promise-based functions by standardizing their error-first callbacks. It handles both standard (err, value) callbacks as well as non-standard callbacks with multiple arguments. Custom promisified functions can be created by overriding the util.promisify.custom symbol. While Bluebird may still be faster, util.promisify is preferable since it is a built-in Node.js core utility and keeps code from depending on third-party dependencies.
1 of 6
Download to read offline
More Related Content
Util.promisify
1. Node.js 8
util.promisify(original)
Fran Herrero
@leynar
github.com/franher
Node.js Barcelona
20 June 2017
2. It converts a callback-based function to a Promise-based
one standard callbacks functions (err, value) =>
5. But bluebird is still faster...
During Node.js 8 lifecycle V8 JS engine will be updated to v6
Right now shipped with V8 JS engine v5.8
Keep your code third dependency agnostic. Use core built-in features!
Editor's Notes
#2: twitter poll
I promise Im gonna be short, then well go to the pub to catch some beers
#3: If you want use an async/await function you should use follow example.
Everybody know we should work and use standards callback function (err, value) => What happen if we dont have standard-callback functions?
#4: * If you promisify one of these functions, it returns an object of values (not a single value).
promisify()handles non-standard callbacks via the internal symbolinternal/util/customPromisifyArgs
https://gist.github.com/franher/11411171213d0537ef48fc0bc6d07bd2
#5: This can be useful for cases where the original function does not follow the standard format of taking an error-first callback as the last argument.
two standard functions have promisified versions due are not error first callback as last arguments but as first
node 8.1.0 landed in https://github.com/nodejs/node/pull/13316/files fs.exists not error-first callback (boolean parameter)
https://gist.github.com/franher/0680a03ae151e8df278c92699f47b92c
#6:
since V8 v5.7 a lot of improvements on perfomance
Node 8 was shipped with V8 v5.8
https://kyrylkov.com/2017/04/25/native-promises-async-functions-nodejs-8-performance/
#7:
since V8 v5.7 a lot of improvements on perfomance
Node 8 was shipped with V8 v5.8
https://kyrylkov.com/2017/04/25/native-promises-async-functions-nodejs-8-performance/