Deploy to GitHub pages
This commit is contained in:
commit
2ef2c469d1
850 changed files with 332608 additions and 0 deletions
24
nimcache/runnableExamples/asyncjs_examples_2.nim
Normal file
24
nimcache/runnableExamples/asyncjs_examples_2.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#[
|
||||
autogenerated by docgen
|
||||
loc: /home/runner/work/Nim/Nim/lib/js/asyncjs.nim(249, 21)
|
||||
rdoccmd: -r:off
|
||||
]#
|
||||
import "/home/runner/work/Nim/Nim/lib/js/asyncjs.nim"
|
||||
{.line: ("/home/runner/work/Nim/Nim/lib/js/asyncjs.nim", 249, 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()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue