1.2.0 • Published 9 years ago
native-promisify v1.2.0
Deprecated, please use thenify or thenify-all
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