-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cancel specific pending lock #64
Comments
Hi @AndreMaz ! Sorry for the late reply. Returning an ID would be the way to go, but this would mean that Imo this makes those methods too quirky just to accomodate an edge case. The same effect can be easily achieved by the application by wrapping the promise returned by the library in another Promise and cancelling that. |
What do you mean by wrapping the promise returned by another library and cancelling that. How would this end up cancelling a specific pending lock? For example if I race lock acqusition like |
You're right, I must've been in a hurry when I wrote the reply above, and the response is a bit misleading. What I really meant is something like: function cancellableAcquire(mutex: Mutex): [Promise<void>, () => void] {
let rejectFn: undefined | (() => void);
let cancelled = false;
return [
new Promise((resolve, reject) => {
rejectFn = reject;
mutex.acquire.then(release => cancelled ? release() : resolve(release), reject);
}),
() => {
cancelled = true;
rejectFn?.();
}
]
} |
Consider allowing |
Yeah, that would work. Of course, the danger with promises is that it is easy to keep track of the original promise, but we could add all Promises to a |
Hi @DirtyHairy thank you for the great lib!
I wanted to ask you if there's a way to
cancel()
some specific pending locks of a mutex? In the docs it statesHowever, in some situations I want to cancel only a specific lock while leaving others waiting for the lock to become available. I took a quick look at the source code but didn't find a way of achieving this. Can you please provide some pointers about how to make this possible?
I guess that the
runExclusive()
will have to return an ID that later can be used to cancel (e.g.,cancel(<ID>)
) the pending lock.The text was updated successfully, but these errors were encountered: