summary refs log tree commit diff stats
path: root/tests/closure/tjester.nim
blob: 48e5186f03e60faa2e56c06b7e1f6924faf1017b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
discard """
  output: '''baro0'''
"""

type
  Future[T] = ref object
    data: T
    callback: proc () {.closure.}

proc cbOuter(response: string) {.closure, discardable.} =
  iterator cbIter(): Future[int] {.closure.} =
    for i in 0..7:
      proc foo(): int =
        iterator fooIter(): Future[int] {.closure.} =
          echo response, i
          yield Future[int](data: 17)
        var iterVar = fooIter
        iterVar().data
      yield Future[int](data: foo())
      
  var iterVar2 = cbIter
  proc cb2() {.closure.} =
    try:
      if not finished(iterVar2):
        let next = iterVar2()
        if next != nil:
          next.callback = cb2
    except:
      echo "WTF"
  cb2()

cbOuter "baro"