n-barrier
Simple barrier implementation for syncing multiple asyncronouse tasks.
Provides two barrier implementations:
nBarrier
which wait forn
tasks to reach their.wait()
instructionpBarrier
which waits for passed in promisses to resolve
installation
npm install n-barrier
usage
nBarrier
Let n
tasks wait for each other before continuing execution.
example
const nBarrier = const barrier = // barrier which wait for 3 tasks before opening const startTask = // no console output for the first 1000ms then// all 'finished' messages will be logged at once
pBarrier
pBarrier
works similar to Promise.all
but you will get back a barrier
instance with
a wait()
method you can pass around to await the resolvement at multiple locations.
const pBarrier = const startTask = const asyncTaskWithBarrier = async { // ...do some stuff await barrier // wait for the other tasks to finish console} const barrier = // starts another aync task await barrierconsole // will only be logged after 1000ms (after each promise resolved)