t22210.nim 730 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. discard """
  2. output: '''
  3. stage 1
  4. stage 2
  5. stage 3
  6. (status: 200, data: "SOMEDATA")
  7. '''
  8. """
  9. import std/asyncdispatch
  10. # bug #22210
  11. type
  12. ClientResponse = object
  13. status*: int
  14. data*: string
  15. proc subFoo1(): Future[int] {.async.} =
  16. await sleepAsync(100)
  17. return 200
  18. proc subFoo2(): Future[string] {.async.} =
  19. await sleepAsync(100)
  20. return "SOMEDATA"
  21. proc testFoo(): Future[ClientResponse] {.async.} =
  22. try:
  23. let status = await subFoo1()
  24. doAssert(status == 200)
  25. let data = await subFoo2()
  26. return ClientResponse(status: status, data: data)
  27. finally:
  28. echo "stage 1"
  29. await sleepAsync(100)
  30. echo "stage 2"
  31. await sleepAsync(200)
  32. echo "stage 3"
  33. when isMainModule:
  34. echo waitFor testFoo()