0.2.12 • Published 4 years ago
promisify.libx.js v0.2.12
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.
0.2.12
4 years ago
0.2.11
4 years ago
0.2.10
4 years ago
0.2.9
4 years ago
0.2.8
4 years ago
0.2.7
4 years ago
0.2.6
4 years ago
0.2.3
4 years ago
0.2.5
4 years ago
0.2.4
4 years ago
0.2.1
4 years ago
0.1.30
4 years ago
0.1.29
4 years ago
0.1.28
4 years ago
0.1.27
4 years ago
0.1.26
4 years ago
0.1.23
4 years ago
0.1.8
4 years ago
0.1.7
4 years ago
0.1.6
4 years ago
0.1.4
4 years ago
0.1.3
4 years ago
0.1.0
4 years ago