enhance-promise
v1.0.3
Published
Simple enhancements for Promises in TS/JS projects
Downloads
1
Readme
Simple enhancements for Promises
// JS Projects
const { PromiseChain, PromiseWrap, PromiseDelay } = require('enhance-promise');
// TS Projects
import { PromiseChain, PromiseDelay, PromiseWrap } from "enhance-promise";
Main features:
PromiseChain (sequential)
const chain: Array<() => Promise<any>> = [
() => this.countDown("3"),
() => this.countDown("2"),
() => this.countDown("1"),
() => this.countDown("GO!")
];
PromiseChain(chain).then(() => {
console.log(`Chain complete`);
});
PromiseWrap
PromiseWrap(() => {
console.log(`Do this without calling resolve`);
}).then(() => {
console.log(`Done`);
})
PromiseDelay
PromiseDelay(1000).then(() => {
console.log(`One second has passed`);
})
Putting it all together
PromiseChain([
() => PromiseWrap(() => console.log(Date.now() + " One")),
() => PromiseDelay(1000),
() => PromiseWrap(() => console.log(Date.now() + " Two")),
() => PromiseDelay(1000),
() => PromiseWrap(() => console.log(Date.now() + " Three")),
() => PromiseDelay(1000),
() => PromiseWrap(() => console.log(Date.now() + " Go!"))
]).then(() => {
console.log("We're done here");
});
Installation
$> npm i enhance-promise
Contributors
Luke Trimby
Licence
MIT