mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-02 05:29:01 +00:00
Deploy to GitHub pages
This commit is contained in:
25
nimcache/runnableExamples/asyncjs_examples_2.nim
Normal file
25
nimcache/runnableExamples/asyncjs_examples_2.nim
Normal file
@@ -0,0 +1,25 @@
|
||||
#[
|
||||
autogenerated by docgen
|
||||
loc: /home/runner/work/Nim/Nim/lib/js/asyncjs.nim(251, 21)
|
||||
rdoccmd: -r:off
|
||||
]#
|
||||
import std/assertions
|
||||
import "/home/runner/work/Nim/Nim/lib/js/asyncjs.nim"
|
||||
{.line: ("/home/runner/work/Nim/Nim/lib/js/asyncjs.nim", 251, 21).}:
|
||||
from std/sugar import `=>`
|
||||
from std/strutils import contains
|
||||
|
||||
proc fn(n: int): Future[int] {.async.} =
|
||||
if n >= 7: raise newException(ValueError, "foobar: " & $n)
|
||||
else: result = n * 2
|
||||
|
||||
proc main() {.async.} =
|
||||
var reason: Error
|
||||
await fn(6).catch((r: Error) => (reason = r)) # note: `()` are needed, `=> reason = r` would not work
|
||||
assert reason == nil
|
||||
await fn(7).catch((r: Error) => (reason = r))
|
||||
assert reason != nil
|
||||
assert "foobar: 7" in $reason.message
|
||||
|
||||
discard main()
|
||||
|
||||
Reference in New Issue
Block a user