パッケージの詳細

cb-barrier

geek39BSD-31.0.3

callback barrier implementation for async/await

readme

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;
};