texceptions.nim 651 B

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