You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd love to implement a maximum wait on removeTokens. Our serverless environment only allows execution time of maximum 30 seconds. I imagine we'd wait 25s, throw an error if we still don't have a token available. The current RateLimiterQueue could wait for hours or even days, which wouldn't work for this usecase.
@bkniffler Hi, this is interesting. I had a look into the codebase. I think it is better to implement an additional parameter for removeTokens method so that the process would be internal. I am afraid it would be not simple to deal with different edge cases if we allow disrupting the queue from outside. I would really try to avoid that.
After a quick check of the code, I think something like this would be the easiest to implement:
Add the second parameter expiresUnixAt = 0 to removeTokens function here
Set it to line 68 like this _this._queueRequest.call(_this, resolve, reject, tokens, expiresUnixAt);.
Add it to the function signature _queueRequest(resolve, reject, tokens, expiresUnixAt = 0) { on line 88 and push when queueing on line 91 _this._queue.push({resolve, reject, tokens, expiresUnixAt});.
Put this sketch of the code (I didn't test it). EDIT: I put nowSecs variable just now, so the code is more robust.
Note, the second check if (_this._queue.length === 0) { is necessary. It isn't mistake. The queue may be empty after expiring items.
This is the easiest since it is built into the normal cycle of FIFO queue processing of items in this package.
If you are going to create a PR for that, please, write at least one test of the new feature.
I hope this helps.
I'd love to implement a maximum wait on removeTokens. Our serverless environment only allows execution time of maximum 30 seconds. I imagine we'd wait 25s, throw an error if we still don't have a token available. The current RateLimiterQueue could wait for hours or even days, which wouldn't work for this usecase.
Thought about something similar to
But noticed that, obviously, the
limiter.removeTokens
is not cancelled and the token is removed even though we wouldn't permit the operation.What do you think, is there any way to solve this without a PR on rate-limiter-flexible? With a PR I could imagine one of these solutions:
limiter.removeTokens
)limiter.removeTokens
)limiter.removeTokens) and add another method
limiter.cancelRemove(id)`What do you think?
The text was updated successfully, but these errors were encountered: