cb-barrier

callback barrier implementation for async/await

BSD-3 3 个版本
安装
npm install cb-barrier
yarn add cb-barrier
pnpm add cb-barrier
bun add cb-barrier
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;
};
版本列表
1.0.3 2018-10-01
1.0.2 2017-11-16
1.0.1 2017-11-16