1.0.3 • Published 7 years ago

cb-barrier v1.0.3

Weekly downloads
6
License
BSD-3
Repository
github
Last release
7 years ago

This is a fork of Teamwork.

Usage

const Barrier = require('cb-barrier');

const main = async () => {
  const barrier = new Barrier();

  setTimeout(() => {
    barrier.pass();
  }, 100);

  await barrier;
};

Pass limits

You can specify a number in the constructor for the number of times a barrier should be passed before it resolves.

const Barrier = require('cb-barrier');

const main = async () => {
  const barrier = new Barrier(2);

  setTimeout(() => {
    barrier.pass();
    barrier.pass();
  }, 100);

  await barrier;
};

Providing return values

const Barrier = require('cb-barrier');

const main = async () => {
  const barrier = new Barrier();

  setTimeout(() => {
    barrier.pass('result');
  }, 100);

  // value equals 'result'
  const value = await barrier;
};