From 3d745a4b0c99b90edffa3fdcddf40783c7776c6b Mon Sep 17 00:00:00 2001 From: Eugene Kabanov Date: Mon, 6 Apr 2020 15:49:09 +0300 Subject: [PATCH] Fix Nim's issue #13889 https://github.com/nim-lang/Nim/issues/13889. (#90) --- chronos/asyncmacro2.nim | 4 +--- tests/testbugs.nim | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/chronos/asyncmacro2.nim b/chronos/asyncmacro2.nim index 2978ba5..eb7822a 100644 --- a/chronos/asyncmacro2.nim +++ b/chronos/asyncmacro2.nim @@ -47,9 +47,7 @@ template createCb(retFutureSym, iteratorNameSym, raise newException(AssertionError, msg % strName) else: {.gcsafe.}: - {.push hint[ConvFromXtoItselfNotNeeded]: off.} - next.callback = identName - {.pop.} + next.addCallback(identName) except CancelledError: retFutureSym.cancel() except CatchableError as exc: diff --git a/tests/testbugs.nim b/tests/testbugs.nim index 5f6b9e1..f1be45f 100644 --- a/tests/testbugs.nim +++ b/tests/testbugs.nim @@ -56,6 +56,23 @@ suite "Asynchronous issues test suite": discard await withTimeout(sleepAsync(4.milliseconds), 4.milliseconds) result = true + proc testMultipleAwait(): Future[bool] {.async.} = + var promise = newFuture[void]() + var checkstr = "" + + proc believers(name: string) {.async.} = + await promise + checkstr = checkstr & name + + asyncCheck believers("Foo") + asyncCheck believers("Bar") + asyncCheck believers("Baz") + + await sleepAsync(100.milliseconds) + promise.complete() + await sleepAsync(100.milliseconds) + result = (checkstr == "FooBarBaz") + test "Issue #6": check waitFor(issue6()) == true @@ -64,3 +81,6 @@ suite "Asynchronous issues test suite": test "Callback-race double completion [withTimeout()] test": check waitFor(testWithTimeout()) == true + + test "Multiple await on single future test [Nim's issue #13889]": + check waitFor(testMultipleAwait()) == true