際際滷

際際滷Share a Scribd company logo
 Node.js 8 
util.promisify(original)
Fran Herrero
@leynar
github.com/franher
Node.js Barcelona
20 June 2017
It converts a callback-based function to a Promise-based
one standard callbacks functions (err, value) =>
non-standard callbacks functions (err, value1, value2, )
=> 
 child_process.exec
 child_process.exec
File
 dns.lookup
 dns.lookupService
 fs.read
 fs.write
ィCustom promisified functions ィ
Symbol util.promisify.custom to override the return value of util.promisify()
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!
Util.promisify

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) =>
  • 3. non-standard callbacks functions (err, value1, value2, ) => child_process.exec child_process.exec File dns.lookup dns.lookupService fs.read fs.write
  • 4. ィCustom promisified functions ィ Symbol util.promisify.custom to override the return value of util.promisify()
  • 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/