Skip to content

Commit

Permalink
RateLimiter: Remove unneeded async statemachine (#6418)
Browse files Browse the repository at this point in the history
* RateLimiter: Remove unneeded async statemachine

* Fix test
  • Loading branch information
benaadams committed Dec 24, 2023
1 parent 3bd89b3 commit 1c0ce55
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Core.Test/RateLimiterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task RateLimiter_should_throw_when_cancelled()
RateLimiter rateLimiter = new(1);
await rateLimiter.WaitAsync(CancellationToken.None);
CancellationTokenSource cts = new();
ValueTask waitTask = rateLimiter.WaitAsync(cts.Token);
Task waitTask = rateLimiter.WaitAsync(cts.Token);
cts.Cancel();

Func<Task> act = async () => await waitTask;
Expand Down
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Core/RateLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public bool IsThrottled()
return GetCurrentTick() < _nextSlot;
}

public async ValueTask WaitAsync(CancellationToken ctx)
public Task WaitAsync(CancellationToken ctx)
{
long currentNextSlot = _nextSlot;
while (true)
Expand All @@ -64,8 +64,8 @@ public async ValueTask WaitAsync(CancellationToken ctx)
long now = GetCurrentTick();
long toWait = currentNextSlot - now;

if (toWait <= 0) return;
if (toWait <= 0) return Task.CompletedTask;

await Task.Delay(TimeSpan.FromMilliseconds(TickToMs(toWait)), ctx);
return Task.Delay(TimeSpan.FromMilliseconds(TickToMs(toWait)), ctx);
}
}

0 comments on commit 1c0ce55

Please sign in to comment.