ts-backpressure
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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

Package Sidebar

Install

npm i ts-backpressure

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

35 kB

Total Files

33

Last publish

Collaborators

  • waltsu