tasyncrecursion.nim 474 B

12345678910111213141516171819202122
  1. discard """
  2. output: "50005000"
  3. """
  4. import asyncdispatch
  5. proc asyncRecursionCycle*(counter: int): Future[int] =
  6. var retFuture = newFuture[int]("asyncRecursionTest")
  7. retFuture.complete(counter + 1)
  8. return retFuture
  9. proc asyncRecursionTest*(): Future[int] {.async.} =
  10. var i = 0
  11. result = 0
  12. while i < 10_000:
  13. inc(result, await asyncRecursionCycle(i))
  14. inc(i)
  15. when true:
  16. setGlobalDispatcher(newDispatcher())
  17. var i = waitFor asyncRecursionTest()
  18. echo i