Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

native-promisify

coderhaoxin164MIT1.2.0

convert callback function to promise only use native promise

promisify, callback, promise, native, es6, co

readme

Deprecated, please use thenify or thenify-all

NPM version Build status Test coverage License Dependency status

native-promisify

var promisify = require('native-promisify');
  • promisify function
function fn(ms, cb) {
  setTimeout(cb(null, ms), ms);
}

var p = promisify(fn);

p(10).then(function(ms) {
  console.log('delay: %d', ms);
});
  • promisify object
var obj = {
  name: 'hello',
  show: fun1,
  tell: fun2,
  ping: fun3
};

// promisify all functions (exclude generator function) of the object
promisify(origin);

// only promisify `show`, `tell`
promisify(origin, ['show', 'tell']);

// filter function
promisify(origin, function(key) {
  return key === 'ping';
});

License

MIT