summary refs log tree commit diff stats
path: root/tests/async
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@gmail.com>2017-02-10 20:18:59 +0100
committerDominik Picheta <dominikpicheta@gmail.com>2017-02-10 20:18:59 +0100
commitddd3d3f44a7bd83d97e17b46bc7fd6b92043520f (patch)
tree2be75d84f608cd7ac2b087c8447247f263b28671 /tests/async
parentd87fb236d101b9c1bc14f18fe17798cc214a9620 (diff)
downloadNim-ddd3d3f44a7bd83d97e17b46bc7fd6b92043520f.tar.gz
Improve implementation of takeAsync for FutureStreams.
Diffstat (limited to 'tests/async')
-rw-r--r--tests/async/tfuturestream.nim26
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