node-redlock icon indicating copy to clipboard operation
node-redlock copied to clipboard

Add ability to cancel lock acquisition

Open dayvsonsales opened this issue 4 years ago • 4 comments

I have a function that requests a lock, but it handles some events, so I would like to cancel the lock acquire if one of the events is fired. I saw the documentation but didn't find anything for this purpose.

dayvsonsales avatar Jan 16 '21 17:01 dayvsonsales

This is not currently possible, but is an interesting idea.

mike-marcacci avatar Mar 23 '21 22:03 mike-marcacci

The RedLock inherits from the Node EventEmitter, so it probably possible to do something:

myLock = require('RedLock');
myLock.on('unlock', function(...args) {
  const parameters = args.join(', ');
  console.log(`parameters ${parameters} for unlock`);
  // some code
});

myLock.emit('unlock', parameters );

can you try it

nivb52 avatar Jun 30 '21 07:06 nivb52

I would definitely be open to providing a mechanism for this using the AbortController standard, but also will likely not have a chance to implement it myself. Marking as "help wanted".

mike-marcacci avatar Nov 26 '21 19:11 mike-marcacci

I will look into it again in the following weeks

nivb52 avatar Jan 20 '22 15:01 nivb52