t13889.nim 527 B

12345678910111213141516171819202122232425262728
  1. discard """
  2. output: '''
  3. believer Foo is saved:true
  4. believer Bar is saved:true
  5. believer Baz is saved:true
  6. '''
  7. """
  8. import asyncdispatch
  9. var
  10. promise = newFuture[bool]()
  11. proc believers(name: string) {.async.} =
  12. let v = await promise
  13. echo "believer " & name & " is saved:" & $v
  14. asyncCheck believers("Foo")
  15. asyncCheck believers("Bar")
  16. asyncCheck believers("Baz")
  17. proc savior() {.async.} =
  18. await sleepAsync(50)
  19. complete(promise, true)
  20. await sleepAsync(50) # give enough time to see who was saved
  21. waitFor(savior())