aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/concurrency/promise.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/concurrency/promise.lux12
1 files changed, 11 insertions, 1 deletions
diff --git a/stdlib/source/lux/concurrency/promise.lux b/stdlib/source/lux/concurrency/promise.lux
index 0dd8ebf00..3c10e785d 100644
--- a/stdlib/source/lux/concurrency/promise.lux
+++ b/stdlib/source/lux/concurrency/promise.lux
@@ -82,12 +82,22 @@
(wrap (list (` (promise' #;None))))))
(def: #export (poll promise)
- {#;doc "Checks whether an Promise's value has already been resolved."}
+ {#;doc "Polls a Promise's value."}
(All [a] (-> (Promise a) (Maybe a)))
(|> (atom;get promise)
io;run
(get@ #value)))
+(def: #export (resolved? promise)
+ {#;doc "Checks whether a Promise's value has already been resolved."}
+ (All [a] (-> (Promise a) Bool))
+ (case (poll promise)
+ #;None
+ false
+
+ (#;Some _)
+ true))
+
(def: #export (resolve value promise)
{#;doc "Sets an Promise's value if it hasn't been done yet."}
(All [a] (-> a (Promise a) (IO Bool)))