Skip to content

Commit

Permalink
Merge pull request nim-lang#11263 from jrfondren/asyncstreams-fix-imm…
Browse files Browse the repository at this point in the history
…ediately-vs-soon

fix unnecessary poll() (and default 500ms delay) in some uses of async
  • Loading branch information
dom96 committed May 16, 2019
2 parents 9d4190a + 22b4cf1 commit f1a8edc
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/pure/asyncstreams.nim
Expand Up @@ -79,7 +79,7 @@ proc read*[T](future: FutureStream[T]): Future[(bool, T)] =
## ``FutureStream``.
var resFut = newFuture[(bool, T)]("FutureStream.take")
let savedCb = future.cb
future.callback =
var newCb =
proc (fs: FutureStream[T]) =
# Exit early if `resFut` is already complete. (See #8994).
if resFut.finished: return
Expand All @@ -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 not savedCb.isNil: savedCb()

if future.queue.len > 0 or future.finished:
newCb(future)
else:
future.callback = newCb
return resFut

proc len*[T](future: FutureStream[T]): int =
Expand Down

0 comments on commit f1a8edc

Please sign in to comment.