tasyncexceptions.nim 941 B

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