Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

caco

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caco

Async generator control flow that supports both callback and promise

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

sema

Async semaphore for shared or exclusive execution of JavaScript functions.

Build Status

npm install sema
var sema = require('sema')
var s = sema()

// exclusive mode
s.acquire(function () {
  ...
  doReadWrite(function (err) {
    ...
    s.release()
  })
})

// shared mode
s.acquire(sema.SHARED, function () {
  ...
  doReadOnly(function (err) {
    ...
    s.release()
  })
})

API

var s = sema()

Creates a semaphore instance.

s.acquire([mode], [fn])

Acquire semaphore. Defaults to exclusive mode. Setting mode sema.SHARED to acquire a shared mode.

Callback to asynchronous function fn when semaphore available. Invoked immediately if semaphore is free or shared only. Otherwise pushed to the wait queue.

Returns a promise if no fn provided. However this yields a slight delay when acquiring, due to the nature of promise. If such timing is important then callback function should be used.

s.release()

Release semaphore.

Invokes function from the wait queue if queue is not empty.

s.mode()

Returns mode constant, the current state of semaphore.

Mode Constants

  • sema.FREE = null
  • sema.SHARED = 1
  • sema.EXCLUSIVE = 2
  • sema.WAIT = 3

License

MIT

FAQs

Package last updated on 11 Feb 2016

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