summary refs log tree commit diff stats
path: root/tests/run/titer8.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-11-17 01:25:32 +0100
committerAraq <rumpf_a@web.de>2012-11-17 01:25:32 +0100
commit7f6633a06feeac8d6bd1eb1e6d8e841591326618 (patch)
tree8476159a24003dfae000de06cecb66b35c32412e /tests/run/titer8.nim
parent7a2c11d3cfef74eaf55ab27adbb1748a04d7904f (diff)
downloadNim-7f6633a06feeac8d6bd1eb1e6d8e841591326618.tar.gz
added system.finished for first class iterators
Diffstat (limited to 'tests/run/titer8.nim')
-rw-r--r--tests/run/titer8.nim40
1 files changed, 39 insertions, 1 deletions
diff --git a/tests/run/titer8.nim b/tests/run/titer8.nim
index e0de6a6b0..34067c414 100644
--- a/tests/run/titer8.nim
+++ b/tests/run/titer8.nim
@@ -14,7 +14,14 @@ ta da1 1
 3 3
 0
 1
-2'''
+2
+a1: A
+a2: A
+a1: B
+a2: B
+a1: C
+a2: C
+a1: D'''
 """
 # Test first class iterator:
 
@@ -77,3 +84,34 @@ proc invoke(iter: proc(): int {.closure.}) =
 
 invoke(count0)
 invoke(count2)
+
+
+# simple tasking:
+type
+  TTask = proc (ticker: int) {.closure.}
+
+iterator a1(ticker: int) {.closure.} =
+  echo "a1: A"
+  yield
+  echo "a1: B"
+  yield
+  echo "a1: C"
+  yield
+  echo "a1: D"
+
+iterator a2(ticker: int) {.closure.} =
+  echo "a2: A"
+  yield
+  echo "a2: B"
+  yield
+  echo "a2: C"
+
+proc runTasks(t: varargs[TTask]) =
+  var ticker = 0
+  while true:
+    let x = t[ticker mod t.len]
+    if finished(x): break
+    x(ticker)
+    inc ticker
+
+runTasks(a1, a2)