summary refs log tree commit diff stats
path: root/lib/pure/concurrency
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/concurrency')
-rw-r--r--lib/pure/concurrency/threadpool.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim
index 72e744d52..2603835dd 100644
--- a/lib/pure/concurrency/threadpool.nim
+++ b/lib/pure/concurrency/threadpool.nim
@@ -267,6 +267,17 @@ proc awaitAny*(flowVars: openArray[FlowVarBase]): int =
     result = -1
   destroySemaphore(ai.cv)
 
+proc isReady*(fv: FlowVarBase): bool =
+  ## Determines whether the specified ``FlowVarBase``'s value is available.
+  ##
+  ## If ``true`` awaiting ``fv`` will not block.
+  if fv.usesSemaphore and not fv.awaited:
+    acquire(fv.cv.L)
+    result = fv.cv.counter > 0
+    release(fv.cv.L)
+  else:
+    result = true
+
 proc nimArgsPassingDone(p: pointer) {.compilerProc.} =
   let w = cast[ptr Worker](p)
   signal(w.taskStarted)