From 2ef34c7339c5d8e59f212d7af72a06e0d3e8327c Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Mon, 5 Jun 2023 13:47:38 +0200 Subject: [PATCH] ratelimit: set cancellation earlier (#402) future may be completed by worker before cancellation is set --- chronos/ratelimit.nim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/chronos/ratelimit.nim b/chronos/ratelimit.nim index 5bf8af9..caaf659 100644 --- a/chronos/ratelimit.nim +++ b/chronos/ratelimit.nim @@ -102,10 +102,6 @@ proc consume*(bucket: TokenBucket, tokens: int): Future[void] = retFuture.complete() return retFuture - bucket.pendingRequests.add(BucketWaiter(future: retFuture, value: tokens)) - if isNil(bucket.workFuture) or bucket.workFuture.finished(): - bucket.workFuture = worker(bucket) - proc cancellation(udata: pointer) = for index in 0..