tasync_misc.nim 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. block: # nkCheckedFieldExpr
  35. proc bar(): Future[JsonNode] {.async.} =
  36. return newJInt(5)
  37. proc foo() {.async.} =
  38. let n = 10 + (await bar()).num
  39. doAssert(n == 15)
  40. waitFor foo()
  41. echo "ok"