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