diff options
Diffstat (limited to 'stdlib/source/library/lux/control/concurrency/async.lux')
-rw-r--r-- | stdlib/source/library/lux/control/concurrency/async.lux | 21 |
1 files changed, 1 insertions, 20 deletions
diff --git a/stdlib/source/library/lux/control/concurrency/async.lux b/stdlib/source/library/lux/control/concurrency/async.lux index 32f1913b6..3dcb864b6 100644 --- a/stdlib/source/library/lux/control/concurrency/async.lux +++ b/stdlib/source/library/lux/control/concurrency/async.lux @@ -18,13 +18,11 @@ ["." atom (#+ Atom atom)]]) (abstract: .public (Async a) - {#.doc "Represents values produced by asynchronous computations (unlike IO, which is synchronous)."} + {} (Atom [(Maybe a) (List (-> a (IO Any)))]) (type: .public (Resolver a) - {#.doc (example "The function used to give a value to an async." - "Will signal 'true' if the async has been resolved for the 1st time, 'false' otherwise.")} (-> a (IO Bit))) (def: (resolver async) @@ -50,25 +48,21 @@ (resolve value)))))))) (def: .public (resolved value) - {#.doc (example "Produces an async that has already been resolved to the given value.")} (All [a] (-> a (Async a))) (:abstraction (atom [(#.Some value) (list)]))) (def: .public (async _) - {#.doc (example "Creates a fresh async that has not been resolved yet.")} (All [a] (-> Any [(Async a) (Resolver a)])) (let [async (:abstraction (atom [#.None (list)]))] [async (..resolver async)])) (def: .public value - {#.doc "Polls an async for its value."} (All [a] (-> (Async a) (IO (Maybe a)))) (|>> :representation atom.read! (\ io.functor map product.left))) (def: .public (upon! f async) - {#.doc (example "Executes the given function as soon as the async has been resolved.")} (All [a] (-> (-> a (IO Any)) (Async a) (IO Any))) (do {! io.monad} [.let [async (:representation async)] @@ -87,7 +81,6 @@ ) (def: .public resolved? - {#.doc "Checks whether an async's value has already been resolved."} (All [a] (-> (Async a) (IO Bit))) (|>> ..value (\ io.functor map @@ -133,7 +126,6 @@ ma)))) (def: .public (and left right) - {#.doc (example "Combines the results of both asyncs, in-order.")} (All [a b] (-> (Async a) (Async b) (Async [a b]))) (let [[read! write!] (:sharing [a b] [(Async a) (Async b)] @@ -150,8 +142,6 @@ read!)) (def: .public (or left right) - {#.doc (example "Yields the results of whichever async gets resolved first." - "You can tell which one was resolved first through pattern-matching.")} (All [a b] (-> (Async a) (Async b) (Async (Or a b)))) (let [[a|b resolve] (..async [])] (with_expansions @@ -166,8 +156,6 @@ a|b)))) (def: .public (either left right) - {#.doc (example "Yields the results of whichever async gets resolved first." - "You cannot tell which one was resolved first.")} (All [a] (-> (Async a) (Async a) (Async a))) (let [[left||right resolve] (..async [])] (`` (exec @@ -179,8 +167,6 @@ left||right)))) (def: .public (schedule! milli_seconds computation) - {#.doc (example "Runs an I/O computation on its own thread (after a specified delay)." - "Returns an async that will eventually host its result.")} (All [a] (-> Nat (IO a) (Async a))) (let [[!out resolve] (..async [])] (exec @@ -192,22 +178,17 @@ !out))) (def: .public future - {#.doc (example "Runs an I/O computation on its own thread." - "Returns an async that will eventually host its result.")} (All [a] (-> (IO a) (Async a))) (..schedule! 0)) (def: .public (delayed milli_seconds value) - {#.doc "Delivers a value after a certain period has passed."} (All [a] (-> Nat a (Async a))) (..schedule! milli_seconds (io value))) (def: .public (delay milli_seconds) - {#.doc "An async that will be resolved after the specified amount of milli-seconds."} (-> Nat (Async Any)) (..delayed milli_seconds [])) (def: .public (time_out milli_seconds async) - {#.doc "Wait for an async to be resolved within the specified amount of milli-seconds."} (All [a] (-> Nat (Async a) (Async (Maybe a)))) (..or (..delay milli_seconds) async)) |