npm

Need private packages and team management tools?Check out npm Orgs. »

aslock

1.0.4 • Public • Published

aslock

Build Status Code Climate Code Coverage npm Version JS Standard

Async lock

Installation

$ npm install aslock --save

Usage

'use strict'
 
const aslock = require('aslock')
const co = require('co')
 
co(function * () {
  // Acquire a lock and do action
  yield aslock.acquire('my-exclusive-work-01', () => co(function * () {
    // Some async actions
    /* ... */
  }))
 
  // Non block without yield
  aslock.acquire('my-exclusive-work-01', () => co(function * () {
    return new Promise((resolve) => setTimeout(resolve, 300))
  }))
 
  try {
    aslock.acquire('my-exclusive-work-01', () => co(function * () {
      /* .. */
    })) // -> This throws error since the lock taken by other.
  } catch (err) {
    console.error('Failed')
  }
}).catch((err) => console.error(err))
 
 

License

This software is released under the MIT License.

Links

Keywords

install

npm i aslock

Downloadsweekly downloads

6

version

1.0.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability