summary refs log tree commit diff stats
path: root/tests/accept
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-08-04 19:47:35 +0200
committerAraq <rumpf_a@web.de>2011-08-04 19:47:35 +0200
commit7a6140e3a4e8bed0af05abe084e3c52cca4070dc (patch)
treef04d3b67aa46530da80a86c473f151c01ded0b93 /tests/accept
parentf0145ba7c5142b2ea7da8c77522600a251145875 (diff)
downloadNim-7a6140e3a4e8bed0af05abe084e3c52cca4070dc.tar.gz
fixes #42
Diffstat (limited to 'tests/accept')
-rw-r--r--tests/accept/compile/tthread_generic.nim35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/accept/compile/tthread_generic.nim b/tests/accept/compile/tthread_generic.nim
new file mode 100644
index 000000000..4ef939408
--- /dev/null
+++ b/tests/accept/compile/tthread_generic.nim
@@ -0,0 +1,35 @@
+type
+  TThreadFuncArgs[T] = object of TObject
+    a: proc(): T {.thread.}
+    b: proc(val: T) {.thread.}
+
+proc handleThreadFunc(arg: TThreadFuncArgs[int]){.thread.} =
+  var func = arg.a
+  var callback = arg.b
+  var output = func()
+  callback(output)
+
+proc `@||->`*[T](func: proc(): T {.thread.}, 
+                 callback: proc(val: T){.thread.}): TThread[TThreadFuncArgs[T]] =
+  var thr: TThread[TThreadFuncArgs[T]]
+  var args: TThreadFuncArgs[T]
+  args.a = func
+  args.b = callback
+  createThread(thr, handleThreadFunc, args)
+  return thr
+
+proc `||->`*[T](func: proc(): T{.thread.}, callback: proc(val: T){.thread.}) =
+  discard func @||-> callback
+
+when isMainModule:
+  import os
+  proc testFunc(): int {.thread.} =
+    return 1
+  proc callbackFunc(val: int) {.thread.} =
+    echo($(val))
+   
+  var thr = (testFunc @||-> callbackFunc)
+  echo("test")
+  joinThread(thr)
+  os.sleep(3000)
+