Various fixes to FutureStreams based on PR feedback.

This commit is contained in:
Dominik Picheta 2017-02-26 12:52:19 +01:00
commit f9cce32097
7 changed files with 72 additions and 48 deletions

View file

@ -1664,6 +1664,17 @@ proc accept*(socket: AsyncFD,
# -- Await Macro
include asyncmacro
proc readAll*(future: FutureStream[string]): Future[string] {.async.} =
## Returns a future that will complete when all the string data from the
## specified future stream is retrieved.
result = ""
while true:
let (hasValue, value) = await future.take()
if hasValue:
result.add(value)
else:
break
proc recvLine*(socket: AsyncFD): Future[string] {.async.} =
## Reads a line of data from ``socket``. Returned future will complete once
## a full line is read or an error occurs.