New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@trex-arms/semaphore

Package Overview
Dependencies
Maintainers
3
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trex-arms/semaphore

A small promise-based semaphore library

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

A semaphore library for node/browsers.

Entry point is ESM.

API

import make_semaphore from '@trex-arms/semaphore'

const delay_1s = () => new Promise(resolve => setTimeout(resolve, 1000))

const semaphore = make_semaphore(2)

const do_stuff = async() => {
	const unlock = await semaphore.lock()
	console.log(`Totally doing work!`)
	await delay_1s()
	unlock()
}

do_stuff() // will start work right away
do_stuff() // will start work right away
do_stuff() // won't start until after one of the other workers finishes

semaphore = make_semaphore(limit)

limit is how many locks are allowed at once.

Returns a semaphore object with two properties:

unlock_function_promise = semaphore.lock()

Returns a promise that resolves as soon as a lock is free. It resolves to an unlock function. Calling that function will release the lock.

locks_free = semaphore.headroom()

Returns the number of unclaimed locks that are currently free.

Keywords

FAQs

Package last updated on 24 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc