1.0.3 • Published 2 years ago

enhance-promise v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago