node package manager


lock one thing

gridlock - lock one thing

The gridlock Node.js module provides a simple locking mechanism for single things.

var gridlock = require('gridlock')
function op (cb) {
  setTimeout(cb, 1000)
var locker = gridlock()
var id = 'abc'
op(function () {
if (locker.lock(id)) {
  locker.once(id, function () {

Returns a new locker which is an instance of EventEmitter.

Tries to store the provided identifier. Returns false if it succeeds and true if it fails meaning the id has already been stored (locked).

  • id String() is the identifier of a thing

Releases the provided identifier and emits it.

  • id String() is the identifier of a thing

To access the Gridlock class require('gridlock').

With npm do:

$ npm install gridlock

MIT License