From 74700fdcab9387843975650ed326937c4d59df9e Mon Sep 17 00:00:00 2001 From: cheatfate Date: Mon, 27 Jan 2020 20:28:44 +0200 Subject: [PATCH] Fix bug cancellation handlers not called in wait() and withTimeout(). Fix double completion bug because of callback race. Fix deprecation warnings. Rename some internal procedures. Bump version to 2.3.5. --- chronos.nimble | 2 +- chronos/asyncfutures2.nim | 40 +++++++++----------- chronos/asyncloop.nim | 68 ++++++++++++++++------------------ chronos/transports/stream.nim | 3 +- tests/testbugs.nim | 23 +++++++++++- tests/testfut.nim | 70 ++++++++++++++++++++++++++++++++++- 6 files changed, 142 insertions(+), 64 deletions(-) diff --git a/chronos.nimble b/chronos.nimble index e3077a0..04543c2 100644 --- a/chronos.nimble +++ b/chronos.nimble @@ -1,5 +1,5 @@ packageName = "chronos" -version = "2.3.4" +version = "2.3.5" author = "Status Research & Development GmbH" description = "Chronos" license = "Apache License 2.0 or MIT" diff --git a/chronos/asyncfutures2.nim b/chronos/asyncfutures2.nim index 4624e2a..16d1b73 100644 --- a/chronos/asyncfutures2.nim +++ b/chronos/asyncfutures2.nim @@ -482,13 +482,12 @@ proc `and`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] {. fut1.callback = cb fut2.callback = cb - proc cancel(udata: pointer) {.gcsafe.} = + proc cancellation(udata: pointer) {.gcsafe.} = # On cancel we remove all our callbacks only. - if not(retFuture.finished()): - fut1.removeCallback(cb) - fut2.removeCallback(cb) + fut1.removeCallback(cb) + fut2.removeCallback(cb) - retFuture.cancelCallback = cancel + retFuture.cancelCallback = cancellation return retFuture proc `or`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] {. @@ -510,13 +509,12 @@ proc `or`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] {. fut1.callback = cb fut2.callback = cb - proc cancel(udata: pointer) {.gcsafe.} = + proc cancellation(udata: pointer) {.gcsafe.} = # On cancel we remove all our callbacks only. - if not(retFuture.finished()): - fut1.removeCallback(cb) - fut2.removeCallback(cb) + fut1.removeCallback(cb) + fut2.removeCallback(cb) - retFuture.cancelCallback = cancel + retFuture.cancelCallback = cancellation return retFuture proc all*[T](futs: varargs[Future[T]]): auto {. @@ -688,17 +686,16 @@ proc allFutures*[T](futs: varargs[Future[T]]): Future[void] = if completedFutures == totalFutures: retFuture.complete() - proc cancel(udata: pointer) {.gcsafe.} = + proc cancellation(udata: pointer) {.gcsafe.} = # On cancel we remove all our callbacks only. - if not(retFuture.finished()): - for i in 0..