texceptions.nim 633 B

1234567891011121314151617181920212223242526272829
  1. discard """
  2. target: "c"
  3. """
  4. import coro
  5. var
  6. stackCheckValue = 1100220033
  7. numbers = newSeqOfCap[int](10)
  8. proc testExceptions(id: int, sleep: float) =
  9. try:
  10. numbers.add(id)
  11. suspend(sleep)
  12. numbers.add(id)
  13. raise (ref ValueError)()
  14. except:
  15. suspend(sleep)
  16. numbers.add(id)
  17. suspend(sleep)
  18. numbers.add(id)
  19. suspend(sleep)
  20. numbers.add(id)
  21. start(proc() = testExceptions(1, 0.01))
  22. start(proc() = testExceptions(2, 0.011))
  23. coro.run()
  24. doAssert(stackCheckValue == 1100220033, "Thread stack got corrupted")
  25. doAssert(numbers == @[1, 2, 1, 2, 1, 2, 1, 2, 1, 2], "Coroutines executed in incorrect order")