-
-
Notifications
You must be signed in to change notification settings - Fork 182
Open
Labels
Description
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
const rateLimit = await Promise.race([
limiter.removeTokens(1),
waitFor(maxWait),
]);
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:
- adding support for CancelablePromise (as second argument on
limiter.removeTokens) - add support for AbortController (as second argument on
limiter.removeTokens) - have an optional ID (as second argument on
limiter.removeTokens) and add another methodlimiter.cancelRemove(id)`
What do you think?