mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 09:24:36 +00:00
* Fix https://github.com/nim-lang/Nim/issues/13889
* Add testcase
* Reduce test time
Co-authored-by: Elie Zedeck RANDRIAMIANDRIRAY <elie.zedeck@gmail.com>
(cherry picked from commit 92c4aad205)
This commit is contained in:
27
tests/async/t13889.nim
Normal file
27
tests/async/t13889.nim
Normal 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())
|
||||
Reference in New Issue
Block a user