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>
This commit is contained in:
Clyybber 2020-04-06 16:25:24 +02:00 • committed by GitHub
commit 92c4aad205
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View file

@ -46,7 +46,7 @@ template createCb(retFutureSym, iteratorNameSym,
else: else:
{.gcsafe.}: {.gcsafe.}:
{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.push hint[ConvFromXtoItselfNotNeeded]: off.}
next.callback = cast[proc() {.closure, gcsafe.}](identName) next.addCallback cast[proc() {.closure, gcsafe.}](identName)
{.pop.} {.pop.}
except: except:
futureVarCompletions futureVarCompletions

27
tests/async/t13889.nim Normal file
View file

@ -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())