rogierschouten/async-lock

[Feature request] maxPending + skip queue behaviour and ability to manually override lock release

louis269279 opened this issue · 2 comments

I have two suggestions for the library:

  1. Currently when you have maxPending enabled with a full queue and the next lock acquire uses skip queue, the next lock acquire with skip-queue priority does not get added to the queue because it errors out saying that the queue is already full. I want it to add to queue, but discard the last item in the queue instead.
    I tweaked the example to illustrate how this should behave.
var lock = new AsyncLock({maxPending: 1});
lock.acquire(key, fn1, cb); // runs immediately
lock.acquire(key, fn2, cb); // added to queue (reached maxPending of 1)
lock.acquire(key, priorityFn, cb, {skipQueue: true}); // jumps queue and basically replaces fn2
  1. I would also like to optionally control when to release the lock.
    Please let me know your thoughts on these

Hi @louis269279

Thank you for the ideas. Some questions:

  1. What would the behavior be of the queue item that gets discarded? An error in the callback?
  2. what more control would you like to have than there already is?

(btw maybe you already know from the README, I do not develop this package, I only merge PRs. So I am happy to think along with you, as long as you are prepared to do the PR)

closing due to inactivity