Skip to content

Instantly share code, notes, and snippets.

@nidate
Created February 22, 2019 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nidate/2afbd6c6730283c332c5dad742e76a60 to your computer and use it in GitHub Desktop.
Save nidate/2afbd6c6730283c332c5dad742e76a60 to your computer and use it in GitHub Desktop.
Promisifyの戻り値
const promisify = require('util.promisify');
/**
* Promisifyはコールバックのパラメータの最初の一つしか返さない。
*
* $ node promisify_test.js
* [ 'a', undefined, undefined ]
* { '0': 'a' }
*/
promisify(function(params, callback) {
return callback(null, 'a', 'b', 'c');
})({}).then(function(result, a, b) {
console.log([result, a, b]);
console.log(arguments);
}).catch((err) => {
console.error(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment