Limit multiple actions - #61
Open
huksley wants to merge 4 commits into
Open
Conversation
peterkhayes
requested changes
Nov 18, 2021
Owner
|
Could you also update the readme, under the Instance Methods section, to add the new parameter? |
huksley
force-pushed
the
multiple-actions
branch
from
November 18, 2021 20:22
1e9df18 to
678cdd9
Compare
Contributor
Author
|
It seems that actionsRemaining is broken for all operations - it always returns N-1, because of I added also test at src/index.test.ts:107 which will not succeed even without my changes it('prevents more than maxInInterval actions within interval', async () => {
const options = { interval: 10, maxInInterval: 2 };
const limiter = await createLimiter(options);
// Should allow first action through.
setTime(0);
// Should have 2 actions available at start
expect(await limiter.wouldLimitWithInfo(id)).toEqual({
actionsRemaining: 2,
blocked: false,
blockedDueToCount: false,
blockedDueToMinDifference: false,
millisecondsUntilAllowed: 0,
});At least that's how I expect library to behave, am I wrong? |
peterkhayes
reviewed
Nov 19, 2021
| if (addNewTimestamp) { | ||
| batch.zadd(key, String(now), uuid()); | ||
| for (let i = 0; i < addNewTimestamps; i++) { | ||
| batch.zadd(key, String(now + i), uuid()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@peterkhayes Hi, here is the pretty naive implementation, would this work?
I think not, because ...Info() methods return always
actionsRemaining == maxInInterval - 1, however, it is my expectation what there would bemaxIntervalavailable.Could you take a look at this? I find all multithreaded programming extremely difficult to implement right.
Feeble attempt to fix #58