Skip to content

Make general semaphore (add an option to limit to # of resources) #5

@bradvogel

Description

@bradvogel

Right now this module implements a binary semaphore pattern: only one resource is allowed inside the critical code block at a time. It would be nice to have an option that allows us to specify the number of resources that are allowed in, so a true semaphore. This API could be something like:

var testLock = new Lock({
  redis: 'redis://localhost:6381',
  namespace: 'mylock',
  number: 5
});

testLock.acquireLock(id, 60 * 1000 /* Lock expires after 60sec if not released */ , function(err, lock) {
   // Up to 5 resources are allowed inside the code block at time
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions