diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/control/concurrency/async.lux | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/stdlib/source/library/lux/control/concurrency/async.lux b/stdlib/source/library/lux/control/concurrency/async.lux index 243d7327f..cc1757a31 100644 --- a/stdlib/source/library/lux/control/concurrency/async.lux +++ b/stdlib/source/library/lux/control/concurrency/async.lux @@ -17,12 +17,12 @@ ["." thread] ["." atom (#+ Atom atom)]]) -(abstract: #export (Async a) - (Atom [(Maybe a) (List (-> a (IO Any)))]) - +(abstract: .public (Async a) {#.doc "Represents values produced by asynchronous computations (unlike IO, which is synchronous)."} - (type: #export (Resolver a) + (Atom [(Maybe a) (List (-> a (IO Any)))]) + + (type: .public (Resolver a) {#.doc (doc "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))) @@ -49,25 +49,25 @@ (in #1)) (resolve value)))))))) - (def: #export (resolved value) + (def: .public (resolved value) {#.doc (doc "Produces an async that has already been resolved to the given value.")} (All [a] (-> a (Async a))) (:abstraction (atom [(#.Some value) (list)]))) - (def: #export (async _) + (def: .public (async _) {#.doc (doc "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: #export poll + (def: .public poll {#.doc "Polls an async for its value."} (All [a] (-> (Async a) (IO (Maybe a)))) (|>> :representation atom.read (\ io.functor map product.left))) - (def: #export (await f async) + (def: .public (await f async) {#.doc (doc "Executes the given function as soon as the async has been resolved.")} (All [a] (-> (-> a (IO Any)) (Async a) (IO Any))) (do {! io.monad} @@ -86,7 +86,7 @@ (await f (:abstraction async)))))))) ) -(def: #export resolved? +(def: .public resolved? {#.doc "Checks whether an async's value has already been resolved."} (All [a] (-> (Async a) (IO Bit))) (|>> ..poll @@ -97,7 +97,7 @@ (#.Some _) #1))))) -(implementation: #export functor +(implementation: .public functor (Functor Async) (def: (map f fa) @@ -105,7 +105,7 @@ (exec (io.run (..await (|>> f resolve) fa)) fb)))) -(implementation: #export apply +(implementation: .public apply (Apply Async) (def: &functor ..functor) @@ -117,7 +117,7 @@ ff)) fb)))) -(implementation: #export monad +(implementation: .public monad (Monad Async) (def: &functor ..functor) @@ -129,7 +129,7 @@ (exec (io.run (..await (..await resolve) mma)) ma)))) -(def: #export (and left right) +(def: .public (and left right) {#.doc (doc "Combines the results of both asyncs, in-order.")} (All [a b] (-> (Async a) (Async b) (Async [a b]))) (let [[read! write!] (:sharing [a b] @@ -146,7 +146,7 @@ left))] read!)) -(def: #export (or left right) +(def: .public (or left right) {#.doc (doc "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)))) @@ -161,7 +161,7 @@ (exec <sides> a|b)))) -(def: #export (either left right) +(def: .public (either left right) {#.doc (doc "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))) @@ -173,7 +173,7 @@ [right])) left||right)))) -(def: #export (schedule millis_delay computation) +(def: .public (schedule millis_delay computation) {#.doc (doc "Runs an I/O computation on its own thread (after a specified delay)." "Returns a aromise that will eventually host its result.")} (All [a] (-> Nat (IO a) (Async a))) @@ -185,23 +185,23 @@ io.run) !out))) -(def: #export future +(def: .public future {#.doc (doc "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: #export (delay time_millis value) +(def: .public (delay time_millis value) {#.doc "Delivers a value after a certain period has passed."} (All [a] (-> Nat a (Async a))) (..schedule time_millis (io value))) -(def: #export (wait time_millis) +(def: .public (wait time_millis) {#.doc "Returns an async that will be resolved after the specified amount of milliseconds."} (-> Nat (Async Any)) (..delay time_millis [])) -(def: #export (time_out time_millis async) +(def: .public (time_out time_millis async) {#.doc "Wait for an async to be resolved within the specified amount of milliseconds."} (All [a] (-> Nat (Async a) (Async (Maybe a)))) (..or (wait time_millis) async)) |