mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
Fixes #6100.
This commit is contained in:
@@ -263,12 +263,12 @@ proc mget*[T](future: FutureVar[T]): var T =
|
||||
## Future has not been finished.
|
||||
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.
|
||||
##
|
||||
## ``True`` may indicate an error or a value. Use ``failed`` to distinguish.
|
||||
when future is FutureVar[T]:
|
||||
result = (Future[T](future)).finished
|
||||
when future is FutureVar:
|
||||
result = (FutureBase(future)).finished
|
||||
else:
|
||||
result = future.finished
|
||||
|
||||
|
||||
@@ -32,6 +32,12 @@ template createCb(retFutureSym, iteratorNameSym,
|
||||
try:
|
||||
if not nameIterVar.finished:
|
||||
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 not retFutureSym.finished:
|
||||
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.} =
|
||||
for i in 0 .. 5:
|
||||
await sleepAsync(1000)
|
||||
await fs.write(i)
|
||||
await sleepAsync(1000)
|
||||
|
||||
echo("Done")
|
||||
fs.complete()
|
||||
|
||||
Reference in New Issue
Block a user