summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-06-02 16:32:41 +0200
committerAraq <rumpf_a@web.de>2015-06-02 16:32:53 +0200
commit79c92603f505c388d370c5ef0dd8890e4e17e4e0 (patch)
tree6f6d7fca4ecef141e90161ffaff23bb3125668a5 /lib
parenta88120ab503192575902a36685c8d59812059829 (diff)
downloadNim-79c92603f505c388d370c5ef0dd8890e4e17e4e0.tar.gz
FlowVar's ^ for refs is safe and convenient to use
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/concurrency/threadpool.nim8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim
index a431691ad..7080e16eb 100644
--- a/lib/pure/concurrency/threadpool.nim
+++ b/lib/pure/concurrency/threadpool.nim
@@ -221,11 +221,17 @@ proc awaitAndThen*[T](fv: FlowVar[T]; action: proc (x: T) {.closure.}) =
     action(fv.blob)
   finished(fv)
 
-proc `^`*[T](fv: FlowVar[ref T]): foreign ptr T =
+proc unsafeRead*[T](fv: FlowVar[ref T]): foreign ptr T =
   ## blocks until the value is available and then returns this value.
   await(fv)
   result = cast[foreign ptr T](fv.data)
 
+proc `^`*[T](fv: FlowVar[ref T]): ref T =
+  ## blocks until the value is available and then returns this value.
+  await(fv)
+  let src = cast[ref T](fv.data)
+  deepCopy result, src
+
 proc `^`*[T](fv: FlowVar[T]): T =
   ## blocks until the value is available and then returns this value.
   await(fv)