diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/concurrency/promise.lux | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/stdlib/source/lux/concurrency/promise.lux b/stdlib/source/lux/concurrency/promise.lux index 0762694f9..2de5fa2c8 100644 --- a/stdlib/source/lux/concurrency/promise.lux +++ b/stdlib/source/lux/concurrency/promise.lux @@ -25,17 +25,11 @@ {#.doc "Represents values produced by asynchronous computations (unlike IO, which is synchronous)."} (Atom (Promise-State a))) -(def: #hidden (promise' ?value) +(def: #export (promise ?value) (All [a] (-> (Maybe a) (Promise a))) (atom {#value ?value #observers (list)})) -(syntax: #export (promise [type s.any]) - {#.doc (doc "Makes an uninitialized Promise (in this example, of Unit)." - (promise Unit))} - (wrap (list (` (: (Promise (~ type)) - (promise' #.None)))))) - (def: #export (poll promise) {#.doc "Polls a Promise's value."} (All [a] (-> (Promise a) (Maybe a))) @@ -88,7 +82,7 @@ (struct: #export _ (F.Functor Promise) (def: (map f fa) - (let [fb (promise ($ +1)) + (let [fb (: (Promise ($ +1)) (promise #.None)) ## fb (promise' #.None) ] (exec (await (function [a] (resolve (f a) fb)) @@ -103,7 +97,7 @@ #observers (list)})) (def: (apply ff fa) - (let [fb (promise ($ +1)) + (let [fb (: (Promise ($ +1)) (promise #.None)) ## fb (promise' #.None) ] (exec (await (function [f] @@ -117,7 +111,7 @@ (def: applicative Applicative<Promise>) (def: (join mma) - (let [ma (promise ($ +0)) + (let [ma (: (Promise ($ +0)) (promise #.None)) ## ma (promise' #.None) ] (exec (await (function [ma'] @@ -137,7 +131,7 @@ (def: #export (alt left right) {#.doc "Heterogeneous alternative combinator."} (All [a b] (-> (Promise a) (Promise b) (Promise (| a b)))) - (let [a|b (promise (| ($ +0) ($ +1))) + (let [a|b (: (Promise (| ($ +0) ($ +1))) (promise #.None)) ## a|b (promise' #.None) ] (with-expansions @@ -154,7 +148,7 @@ (def: #export (either left right) {#.doc "Homogeneous alternative combinator."} (All [a] (-> (Promise a) (Promise a) (Promise a))) - (let [left||right (promise ($ +0)) + (let [left||right (: (Promise ($ +0)) (promise #.None)) ## left||right (promise' #.None) ] (`` (exec (~~ (do-template [<promise>] @@ -168,7 +162,7 @@ (def: #export (future computation) {#.doc "Runs an I/O computation on its own process and returns an Promise that will eventually host its result."} (All [a] (-> (IO a) (Promise a))) - (let [!out (promise ($ +0)) + (let [!out (: (Promise ($ +0)) (promise #.None)) ## !out (promise' #.None) ] (exec ("lux process future" (io (io.run (resolve (io.run computation) @@ -178,7 +172,7 @@ (def: #export (wait time) {#.doc "Returns a Promise that will be resolved after the specified amount of milliseconds."} (-> Nat (Promise Unit)) - (let [!out (promise Unit)] + (let [!out (: (Promise Unit) (promise #.None))] (exec ("lux process schedule" time (resolve [] !out)) !out))) |