Merge pull request #11263 from jrfondren/asyncstreams-fix-immediately-vs-soon
fix unnecessary poll() (and default 500ms delay) in some uses of async
This commit is contained in:
commit
f1a8edc14d
1 changed files with 6 additions and 1 deletions
|
|
@ -79,7 +79,7 @@ proc read*[T](future: FutureStream[T]): Future[(bool, T)] =
|
||||||
## ``FutureStream``.
|
## ``FutureStream``.
|
||||||
var resFut = newFuture[(bool, T)]("FutureStream.take")
|
var resFut = newFuture[(bool, T)]("FutureStream.take")
|
||||||
let savedCb = future.cb
|
let savedCb = future.cb
|
||||||
future.callback =
|
var newCb =
|
||||||
proc (fs: FutureStream[T]) =
|
proc (fs: FutureStream[T]) =
|
||||||
# Exit early if `resFut` is already complete. (See #8994).
|
# Exit early if `resFut` is already complete. (See #8994).
|
||||||
if resFut.finished: return
|
if resFut.finished: return
|
||||||
|
|
@ -100,6 +100,11 @@ proc read*[T](future: FutureStream[T]): Future[(bool, T)] =
|
||||||
|
|
||||||
# If the saved callback isn't nil then let's call it.
|
# If the saved callback isn't nil then let's call it.
|
||||||
if not savedCb.isNil: savedCb()
|
if not savedCb.isNil: savedCb()
|
||||||
|
|
||||||
|
if future.queue.len > 0 or future.finished:
|
||||||
|
newCb(future)
|
||||||
|
else:
|
||||||
|
future.callback = newCb
|
||||||
return resFut
|
return resFut
|
||||||
|
|
||||||
proc len*[T](future: FutureStream[T]): int =
|
proc len*[T](future: FutureStream[T]): int =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue