summary refs log tree commit diff stats
path: root/tests/async/tasyncrecursion.nim
blob: 7c12dbb0ee69a79efe29849b52defe8e74e2c78c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
discard """
output: "50005000"
"""
import asyncdispatch

proc asyncRecursionCycle*(counter: int): Future[int] =
  var retFuture = newFuture[int]("asyncRecursionTest")
  retFuture.complete(counter + 1)
  return retFuture

proc asyncRecursionTest*(): Future[int] {.async.} =
  var i = 0
  result = 0
  while i < 10_000:
    inc(result, await asyncRecursionCycle(i))
    inc(i)

when true:
  setGlobalDispatcher(newDispatcher())
  var i = waitFor asyncRecursionTest()
  echo i