@esutils/async-semaphore
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

A minimal async semaphore library that implemented in typescript

This async semaphore library can be used by es module, commonjs module and typescript module

Examples

Usage in typescript module, file with .ts extension

import { AsyncSemaphore } from '@esutils/async-semaphore';

const semaphore = new AsyncSemaphore(1);
const steps: string[] = [];

async function operation1() {
  steps.push('operation1.1');
  await semaphore.acquire();
  steps.push('operation1.2');
  await semaphore.release();
}

async function operation2() {
  steps.push('operation2.1');
  await semaphore.acquire();
  steps.push('operation2.2');
  await semaphore.release();
}

async function demo() {
  await Promise.all([operation1(), operation2()]);
  console.log(steps);
}
demo();

Package Sidebar

Install

npm i @esutils/async-semaphore

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

18.4 kB

Total Files

23

Last publish

Collaborators

  • lygstate