tasync_misc.nim 837 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. discard """
  2. exitcode: 0
  3. output: "ok"
  4. """
  5. import json, asyncdispatch
  6. block: #6100
  7. let done = newFuture[int]()
  8. done.complete(1)
  9. proc asyncSum: Future[int] {.async.} =
  10. for _ in 1..10_000_000:
  11. result += await done
  12. let res = waitFor asyncSum()
  13. doAssert(res == 10000000)
  14. block: #7985
  15. proc getData(): Future[JsonNode] {.async.} =
  16. result = %*{"value": 1}
  17. type
  18. MyData = object
  19. value: BiggestInt
  20. proc main() {.async.} =
  21. let data = to(await(getData()), MyData)
  22. doAssert($data == "(value: 1)")
  23. waitFor(main())
  24. block: #8399
  25. proc bar(): Future[string] {.async.} = discard
  26. proc foo(line: string) {.async.} =
  27. var res =
  28. case line[0]
  29. of '+', '-': @[]
  30. of '$': (let x = await bar(); @[""])
  31. else: @[]
  32. doAssert(res == @[""])
  33. waitFor foo("$asd")
  34. echo "ok"