enhance-promise
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i enhance-promise

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

3.95 kB

Total Files

5

Last publish

Collaborators

  • luke-trimby
  • lukas-one-acc