titerators.nim 735 B

1234567891011121314151617181920212223242526272829303132
  1. discard """
  2. targets: "c"
  3. disabled: true
  4. """
  5. # Timers are always flakey on the testing servers.
  6. import coro
  7. include system/timers
  8. var
  9. stackCheckValue = 1100220033
  10. numbers = newSeqOfCap[int](10)
  11. iterator theIterator(id: int, sleep: float): int =
  12. for i in 0..<5:
  13. yield 10 * id + i
  14. suspend(sleep)
  15. proc theCoroutine(id: int, sleep: float32) =
  16. for n in theIterator(id, sleep):
  17. numbers.add(n)
  18. var start = getTicks()
  19. start(proc() = theCoroutine(1, 0.01))
  20. start(proc() = theCoroutine(2, 0.011))
  21. run()
  22. var executionTime = getTicks() - start
  23. doAssert(stackCheckValue == 1100220033, "Thread stack got corrupted")
  24. doAssert(numbers == @[10, 20, 11, 21, 12, 22, 13, 23, 14, 24], "Coroutines executed in incorrect order")