Iterators test in coroutines
This commit is contained in:
parent
ff1bf74554
commit
ce4e9846f0
1 changed files with 19 additions and 0 deletions
|
|
@ -339,3 +339,22 @@ when isMainModule:
|
||||||
run()
|
run()
|
||||||
doAssert order == @[1, 2, 1, 1, 1, 2, 2, 1, 2, 2]
|
doAssert order == @[1, 2, 1, 1, 1, 2, 2, 1, 2, 2]
|
||||||
doAssert stackCheckValue == 1100220033
|
doAssert stackCheckValue == 1100220033
|
||||||
|
|
||||||
|
order = newSeq[int](10)
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
iterator suspendingIterator(sleep: float): int =
|
||||||
|
for i in 0..4:
|
||||||
|
yield i
|
||||||
|
suspend(sleep)
|
||||||
|
|
||||||
|
proc terstIterators(id: int, sleep: float) =
|
||||||
|
for n in suspendingIterator(sleep):
|
||||||
|
order[i] = n
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
start(proc() = terstIterators(1, 0.01))
|
||||||
|
start(proc() = terstIterators(2, 0.021))
|
||||||
|
run()
|
||||||
|
doAssert order == @[0, 0, 1, 2, 1, 3, 4, 2, 3, 4]
|
||||||
|
doAssert stackCheckValue == 1100220033
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue