promisify.libx.js
v0.2.12
Published
Promises made easy
Downloads
49
Readme
Promisify.libx.js
Create promises as an object to manually wrapper for non-promisified functions.
While util.promisify
is useful to convert callback-based functions to promisibable functions, promisify.libx.js
is useful to manually manage resolve
and reject
operations.
Instead:
const stat = util.promisify(fs.stat);
stat('.').then((stats) => {
// Do something with `stats`
}).catch((error) => {
// Handle the error.
});
Do:
const Promisify = require('promisify.libx.js');
const p = Promisify.new();
fs.stat('.').then(stats=>{
p.resolve(stats);
}).catch(error => {
p.reject(error);
});
const stat = await p;
This approach allows easier to turn deep callback-based functions, spagetti or legacy code, into more modern promisiable code with fewer changes.
Develop:
Build:
$ yarn build
Watch & Build:
$ yarn watch
Run tests:
$ yarn test
Usage:
Check tests.