parent
65c7884a3c
commit
2039e3e883
2 changed files with 21 additions and 7 deletions
|
|
@ -207,6 +207,9 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
||||||
futureVarIdents)
|
futureVarIdents)
|
||||||
# don't do anything with forward bodies (empty)
|
# don't do anything with forward bodies (empty)
|
||||||
if procBody.kind != nnkEmpty:
|
if procBody.kind != nnkEmpty:
|
||||||
|
# fix #13899, defer should not escape its original scope
|
||||||
|
procBody = newStmtList(newTree(nnkBlockStmt, newEmptyNode(), procBody))
|
||||||
|
|
||||||
procBody.add(createFutureVarCompletions(futureVarIdents, nil))
|
procBody.add(createFutureVarCompletions(futureVarIdents, nil))
|
||||||
|
|
||||||
if not subtypeIsVoid:
|
if not subtypeIsVoid:
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,3 @@
|
||||||
discard """
|
|
||||||
exitcode: 0
|
|
||||||
output: "ok"
|
|
||||||
"""
|
|
||||||
|
|
||||||
import json, asyncdispatch
|
import json, asyncdispatch
|
||||||
block: #6100
|
block: #6100
|
||||||
let done = newFuture[int]()
|
let done = newFuture[int]()
|
||||||
|
|
@ -61,5 +56,21 @@ block: # 12743
|
||||||
|
|
||||||
waitFor prc()
|
waitFor prc()
|
||||||
|
|
||||||
|
block: # issue #13899
|
||||||
echo "ok"
|
proc someConnect() {.async.} =
|
||||||
|
await sleepAsync(1)
|
||||||
|
proc someClose() {.async.} =
|
||||||
|
await sleepAsync(2)
|
||||||
|
proc testFooFails(): Future[bool] {.async.} =
|
||||||
|
await someConnect()
|
||||||
|
defer:
|
||||||
|
await someClose()
|
||||||
|
result = true
|
||||||
|
proc testFooSucceed(): Future[bool] {.async.} =
|
||||||
|
try:
|
||||||
|
await someConnect()
|
||||||
|
finally:
|
||||||
|
await someClose()
|
||||||
|
result = true
|
||||||
|
doAssert waitFor testFooSucceed()
|
||||||
|
doAssert waitFor testFooFails()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue