Fixes #6100.
This commit is contained in:
parent
7937e38423
commit
52cc925e0e
4 changed files with 25 additions and 4 deletions
|
|
@ -263,12 +263,12 @@ proc mget*[T](future: FutureVar[T]): var T =
|
||||||
## Future has not been finished.
|
## Future has not been finished.
|
||||||
result = Future[T](future).value
|
result = Future[T](future).value
|
||||||
|
|
||||||
proc finished*[T](future: Future[T] | FutureVar[T]): bool =
|
proc finished*(future: FutureBase | FutureVar): bool =
|
||||||
## Determines whether ``future`` has completed.
|
## Determines whether ``future`` has completed.
|
||||||
##
|
##
|
||||||
## ``True`` may indicate an error or a value. Use ``failed`` to distinguish.
|
## ``True`` may indicate an error or a value. Use ``failed`` to distinguish.
|
||||||
when future is FutureVar[T]:
|
when future is FutureVar:
|
||||||
result = (Future[T](future)).finished
|
result = (FutureBase(future)).finished
|
||||||
else:
|
else:
|
||||||
result = future.finished
|
result = future.finished
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,12 @@ template createCb(retFutureSym, iteratorNameSym,
|
||||||
try:
|
try:
|
||||||
if not nameIterVar.finished:
|
if not nameIterVar.finished:
|
||||||
var next = nameIterVar()
|
var next = nameIterVar()
|
||||||
|
# Continue while the yielded future is already finished.
|
||||||
|
while (not next.isNil) and next.finished:
|
||||||
|
next = nameIterVar()
|
||||||
|
if nameIterVar.finished:
|
||||||
|
break
|
||||||
|
|
||||||
if next == nil:
|
if next == nil:
|
||||||
if not retFutureSym.finished:
|
if not retFutureSym.finished:
|
||||||
let msg = "Async procedure ($1) yielded `nil`, are you await'ing a " &
|
let msg = "Async procedure ($1) yielded `nil`, are you await'ing a " &
|
||||||
|
|
|
||||||
15
tests/async/t6100.nim
Normal file
15
tests/async/t6100.nim
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
discard """
|
||||||
|
file: "t6100.nim"
|
||||||
|
exitcode: 0
|
||||||
|
output: "10000000"
|
||||||
|
"""
|
||||||
|
import asyncdispatch
|
||||||
|
|
||||||
|
let done = newFuture[int]()
|
||||||
|
done.complete(1)
|
||||||
|
|
||||||
|
proc asyncSum: Future[int] {.async.} =
|
||||||
|
for _ in 1..10_000_000:
|
||||||
|
result += await done
|
||||||
|
|
||||||
|
echo waitFor asyncSum()
|
||||||
|
|
@ -18,8 +18,8 @@ var fs = newFutureStream[int]()
|
||||||
|
|
||||||
proc alpha() {.async.} =
|
proc alpha() {.async.} =
|
||||||
for i in 0 .. 5:
|
for i in 0 .. 5:
|
||||||
await sleepAsync(1000)
|
|
||||||
await fs.write(i)
|
await fs.write(i)
|
||||||
|
await sleepAsync(1000)
|
||||||
|
|
||||||
echo("Done")
|
echo("Done")
|
||||||
fs.complete()
|
fs.complete()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue