-
Notifications
You must be signed in to change notification settings - Fork 178
Open
Description
Hi,
We are using redlock in a big project, and I started looking into upgrading since we want to upgrade ioredis to v5. A few suggestions:
- can we have a double signature on the
acquire
function so it accepts both a string and an array of strings. this will make migrating much easier for most users. And I think in general the more common usecase will be a lock on 1 resource:
public async acquire(
resources: string | string[],
- why can the lock.release() still throw an error? in the examples you put
lock.release()
in thefinally
section, however this function can also throw an ExecutionError. So we would have to do something like this:
let lock: Lock | null = null;
try {
lock = await redLock.acquire([`...`], 15000);
// do some stuff
} catch (error) {
if (error instanceOf ResourceLockedError) {
console.log('failed to acquire the lock on the resource');
}
console.log(error)
} finally {
await lock?.release().catch(ExecutionError, () => {
console.log('failed to release the lock on the update. This can indicate that the lock expired prior to unlocking it');
});
}
this makes everything a bit convoluted. I would let the release of the lock fail silently.
Metadata
Metadata
Assignees
Labels
No labels