diff options
author | Dominik Picheta <dominikpicheta@gmail.com> | 2017-02-10 20:18:59 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@gmail.com> | 2017-02-10 20:18:59 +0100 |
commit | ddd3d3f44a7bd83d97e17b46bc7fd6b92043520f (patch) | |
tree | 2be75d84f608cd7ac2b087c8447247f263b28671 /tests/async | |
parent | d87fb236d101b9c1bc14f18fe17798cc214a9620 (diff) | |
download | Nim-ddd3d3f44a7bd83d97e17b46bc7fd6b92043520f.tar.gz |
Improve implementation of takeAsync for FutureStreams.
Diffstat (limited to 'tests/async')
-rw-r--r-- | tests/async/tfuturestream.nim | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/tests/async/tfuturestream.nim b/tests/async/tfuturestream.nim index e3480126f..61b3863ac 100644 --- a/tests/async/tfuturestream.nim +++ b/tests/async/tfuturestream.nim @@ -14,21 +14,39 @@ Finished """ import asyncdispatch -var fs = newFutureStream[string]() +var fs = newFutureStream[int]() proc alpha() {.async.} = for i in 0 .. 5: await sleepAsync(1000) - fs.put($i) + fs.put(i) - fs.complete("Done") + fs.complete() proc beta() {.async.} = while not fs.finished: - echo(await fs.takeAsync()) + let (hasValue, value) = await fs.takeAsync() + if hasValue: + echo(value) echo("Finished") asyncCheck alpha() waitFor beta() +# TODO: Something like this should work eventually. +# proc delta(): FutureStream[string] {.async.} = +# for i in 0 .. 5: +# await sleepAsync(1000) +# result.put($i) + +# return "" + +# proc omega() {.async.} = +# let fut = delta() +# while not fut.finished(): +# echo(await fs.takeAsync()) + +# echo("Finished") + +# waitFor omega() \ No newline at end of file |