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