t22210_2.nim 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import std/asyncdispatch
  2. # bug #22210
  3. type
  4. ClientResponse = object
  5. status*: int
  6. data*: string
  7. proc subFoo1(): Future[int] {.async.} =
  8. await sleepAsync(100)
  9. return 200
  10. proc subFoo2(): Future[string] {.async.} =
  11. await sleepAsync(100)
  12. return "SOMEDATA"
  13. proc testFoo2(): Future[ClientResponse] {.async.} =
  14. var flag = 0
  15. try:
  16. let status = await subFoo1()
  17. doAssert(status == 200)
  18. let data = await subFoo2()
  19. result = ClientResponse(status: status, data: data)
  20. finally:
  21. inc flag
  22. await sleepAsync(100)
  23. inc flag
  24. await sleepAsync(200)
  25. inc flag
  26. doAssert flag == 3
  27. discard waitFor testFoo2()
  28. proc testFoo3(): Future[ClientResponse] {.async.} =
  29. var flag = 0
  30. try:
  31. let status = await subFoo1()
  32. doAssert(status == 200)
  33. let data = await subFoo2()
  34. if false:
  35. return ClientResponse(status: status, data: data)
  36. finally:
  37. inc flag
  38. await sleepAsync(100)
  39. inc flag
  40. await sleepAsync(200)
  41. inc flag
  42. doAssert flag == 3
  43. discard waitFor testFoo3()
  44. proc testFoo4(): Future[ClientResponse] {.async.} =
  45. var flag = 0
  46. try:
  47. let status = await subFoo1()
  48. doAssert(status == 200)
  49. let data = await subFoo2()
  50. if status == 200:
  51. return ClientResponse(status: status, data: data)
  52. else:
  53. return ClientResponse()
  54. finally:
  55. inc flag
  56. await sleepAsync(100)
  57. inc flag
  58. await sleepAsync(200)
  59. inc flag
  60. doAssert flag == 3
  61. discard waitFor testFoo4()