0.1.0 • Published 4 years ago

ts-backpressure v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Backpressure

Library for applying backpressure to the function invocations.

Usage

import { Backpressure } from './backpressure';

const sleep = async () => {
  await new Promise(resolve => setTimeout(resolve, 1000));
};

const backpressure = new Backpressure(1); // Allow only one call to be inflight
const backpressuredSleep = backpressure.wrap(sleep);

const promises = Array.from(Array(3)).map(backpressuredSleep);

await Promise.all(promises); // Resolves after 3 seconds