diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index c6f4ae04a..4faddb4f8 100644 --- a/lib/pure/asyncmacro.nim +++ b/lib/pure/asyncmacro.nim @@ -46,7 +46,7 @@ template createCb(retFutureSym, iteratorNameSym, else: {.gcsafe.}: {.push hint[ConvFromXtoItselfNotNeeded]: off.} - next.callback = cast[proc() {.closure, gcsafe.}](identName) + next.addCallback cast[proc() {.closure, gcsafe.}](identName) {.pop.} except: futureVarCompletions diff --git a/tests/async/t13889.nim b/tests/async/t13889.nim new file mode 100644 index 000000000..fe75fe38a --- /dev/null +++ b/tests/async/t13889.nim @@ -0,0 +1,27 @@ +discard """ + output: ''' +believer Foo is saved:true +believer Bar is saved:true +believer Baz is saved:true +''' +""" + +import asyncdispatch + +var + promise = newFuture[bool]() + +proc believers(name: string) {.async.} = + let v = await promise + echo "believer " & name & " is saved:" & $v + +asyncCheck believers("Foo") +asyncCheck believers("Bar") +asyncCheck believers("Baz") + +proc savior() {.async.} = + await sleepAsync(50) + complete(promise, true) + await sleepAsync(50) # give enough time to see who was saved + +waitFor(savior())