tasyncjs_bad.nim 535 B

1234567891011121314151617181920212223
  1. discard """
  2. exitCode: 1
  3. outputsub: "Error: unhandled exception: foobar: 13"
  4. """
  5. # note: this needs `--unhandled-rejections=strict`, see D20210217T215950
  6. import std/asyncjs
  7. from std/sugar import `=>`
  8. proc fn(n: int): Future[int] {.async.} =
  9. if n >= 7: raise newException(ValueError, "foobar: " & $n)
  10. else: result = n
  11. proc main() {.async.} =
  12. let x1 = await fn(6)
  13. doAssert x1 == 6
  14. await fn(7).catch((a: Error) => (discard))
  15. let x3 = await fn(13)
  16. doAssert false # shouldn't go here, should fail before
  17. discard main()