Skip to content
This repository has been archived by the owner on Nov 27, 2021. It is now read-only.

yusukeshib/concurrent-lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

concurrent-lock

Promise based lock object supporting simultaneous access limit.

Install

npm install concurrent-lock

Usage

Create lock object with concurrent limit.

import Lock from 'concurrent-lock'

// concurrent access limit = 1
const simultaneous_limit = 2
const lock = new Lock(simultaneous_limit)

async somefunc() {
  await lock.lock()
  // ...some async proc...
  lock.unlock()

  // you can set timeout argument as millisec
  // Timeout error will be thrown if lock couldn't acquire within specified timeout millisec.
  await lock.lock(3000)
  // ...some async proc...
  lock.unlock()
}

Author

Yusuke Shibata

Licence

MIT

About

Promise based lock object supporting semaphore.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published