waitwait
v0.3.0
Published
Golang's `WaitGroup` and Unix's `sleep` for Javascript (browser and Node.js).
Downloads
6
Maintainers
Readme
WaitWait
WIP
Tiny implementation of Golang's WaitGroup
and Unix's sleep
for Javascript (browser and Node.js), with promises and zero dependencies.
Install
With NPM:
npm install waitwait --save
or with Yarn:
yarn add waitwait
Usage
Sleep
sleep (wait) 1 seconde:
import {sleep} from 'waitwait';
console.log('Start');
await sleep(1000);
console.log('End');
WaitGroup
Waits until the routine is done:
import {WaitGroup} from 'waitwait';
const wg = new WaitGroup();
wg.add();
console.log('Start');
setTimeout(() => {
wg.done();
}, 1000);
await wg.wait();
console.log('End');
Waits until all routines are done:
import {WaitGroup} from 'waitwait';
const wg = new WaitGroup();
wg.add(2);
console.log('Start');
setTimeout(() => {
wg.done();
}, 1000);
setTimeout(() => {
wg.done();
}, 4000);
await wg.wait();
console.log('End');
Waits forever:
import {WaitGroup} from 'waitwait';
const wg = new WaitGroup();
console.log('Start');
wg.add();
console.log('This process is running forever');
await wg.wait();
console.log('End');
Cancel a WaitGroup
:
import {WaitGroup} from 'waitwait';
const wg = new WaitGroup();
// Add 10 routines
wg.add(10);
console.log('Start');
// Cancel all routines after 2 secondes
setTimeout(() => {
wg.cancel();
}, 2000);
await wg.wait();
console.log('End');
LICENSE
MIT (c) 2021, Nicolas Tallefourtane.
Author
| | |---| | Nicolas Talle | | |