From 03d82475d91c09d35faace9077c8f2050a0bfc2e Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Wed, 6 Mar 2024 06:42:22 +0100 Subject: [PATCH] Avoid `ValueError` effect in varargs `race`/`one` (#520) We can check at compile-time that at least one parameter is passed * clean up closure environment explicitly in some callbacks to release memory earlier --- chronos/internal/asyncfutures.nim | 174 +++++++++++++++++++----------- tests/testfut.nim | 31 ++++-- 2 files changed, 136 insertions(+), 69 deletions(-) diff --git a/chronos/internal/asyncfutures.nim b/chronos/internal/asyncfutures.nim index d0842520..d364dc55 100644 --- a/chronos/internal/asyncfutures.nim +++ b/chronos/internal/asyncfutures.nim @@ -734,8 +734,8 @@ proc `and`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] {. retFuture.fail(fut2.error) else: retFuture.complete() - fut1.callback = cb - fut2.callback = cb + fut1.addCallback(cb) + fut2.addCallback(cb) proc cancellation(udata: pointer) = # On cancel we remove all our callbacks only. @@ -1086,12 +1086,14 @@ proc allFutures*(futs: varargs[FutureBase]): Future[void] {. inc(finishedFutures) if finishedFutures == totalFutures: retFuture.complete() + reset(nfuts) proc cancellation(udata: pointer) = # On cancel we remove all our callbacks only. for i in 0..