@lancercomet/lib.semaphore
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@lancercomet/lib.semaphore

This is a simple semaphore implementation.

Quick start

import { Semaphore } from '@lancercomet/lib.semaphore'

// A semaphore with available and max count in 3.
const semaphore = new Semaphore(3, 3)

// Download 3 images at same time.
const downloadImage = async (imageUrl: string) => {
  await semaphore.waitAsync()
  // Do some download work...
  semaphore.release()
}

const imageList: string[] = []
imageList.forEach(imageUrl => downloadImage(imageUrl))

Readme

Keywords

Package Sidebar

Install

npm i @lancercomet/lib.semaphore

Weekly Downloads

0

Version

1.0.1

License

Apache-2.0

Unpacked Size

17.1 kB

Total Files

6

Last publish

Collaborators

  • pwch