diff options
author | Clyybber <darkmine956@gmail.com> | 2020-04-06 16:25:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-06 16:25:24 +0200 |
commit | 92c4aad2059a350e95bc7a64932873b41b085976 (patch) | |
tree | 44875504f0e02d04851cbec909777437d8774e94 | |
parent | 1e25e16c8834324006e8ce00e20e6d59e6c5cf6f (diff) | |
download | Nim-92c4aad2059a350e95bc7a64932873b41b085976.tar.gz |
Fix #13889 with testcase (#13896) [backport]
* Fix https://github.com/nim-lang/Nim/issues/13889 * Add testcase * Reduce test time Co-authored-by: Elie Zedeck RANDRIAMIANDRIRAY <elie.zedeck@gmail.com>
-rw-r--r-- | lib/pure/asyncmacro.nim | 2 | ||||
-rw-r--r-- | tests/async/t13889.nim | 27 |
2 files changed, 28 insertions, 1 deletions
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()) |