tasyncexceptions.nim 906 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. discard """
  2. outputsub: "Error: unhandled exception: foobar"
  3. exitcode: 1
  4. """
  5. import asyncdispatch
  6. # Note: This is a test case for a bug.
  7. proc accept(): Future[int] {.async.} =
  8. await sleepAsync(100)
  9. result = 4
  10. proc recvLine(fd: int): Future[string] {.async.} =
  11. await sleepAsync(100)
  12. return "get"
  13. proc processClient(fd: int) {.async.} =
  14. # these finish synchronously, we need some async delay to emulate this bug.
  15. var line = await recvLine(fd)
  16. var foo = line[0]
  17. if foo == 'g':
  18. raise newException(Exception, "foobar")
  19. proc serve() {.async.} =
  20. while true:
  21. var fut = await accept()
  22. await processClient(fut)
  23. when true:
  24. proc main =
  25. var fut = serve()
  26. fut.callback =
  27. proc () =
  28. if fut.failed:
  29. # This test ensures that this exception crashes the application
  30. # as it is not handled.
  31. raise fut.error
  32. runForever()
  33. main()