diff options
author | Eduardo Julian | 2018-05-08 22:30:03 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-05-08 22:30:03 -0400 |
commit | 8c90251c12a4d0d4cc191bfb273bb5eb51bb0356 (patch) | |
tree | 5964bba6bedd134c244bc322df4cced3419ca957 /stdlib/source | |
parent | ca9541c0c10d4e6aa94055ecfb47301ed7292828 (diff) |
- Re-named "lux process concurrency-level" to "lux process parallelism-level".
- Merged the functionality of "lux process future" into "lux process schedule".
Diffstat (limited to 'stdlib/source')
-rw-r--r-- | stdlib/source/lux/concurrency/promise.lux | 40 | ||||
-rw-r--r-- | stdlib/source/lux/test.lux | 2 |
2 files changed, 23 insertions, 19 deletions
diff --git a/stdlib/source/lux/concurrency/promise.lux b/stdlib/source/lux/concurrency/promise.lux index 63305f318..a2311d272 100644 --- a/stdlib/source/lux/concurrency/promise.lux +++ b/stdlib/source/lux/concurrency/promise.lux @@ -9,9 +9,9 @@ (concurrency [atom #+ Atom atom]) (type abstract))) -(def: #export concurrency-level +(def: #export parallelism-level Nat - ("lux process concurrency-level")) + ("lux process parallelism-level")) (abstract: #export (Promise a) {#.doc "Represents values produced by asynchronous computations (unlike IO, which is synchronous)."} @@ -139,27 +139,31 @@ [right])) left||right)))) -(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))) +(def: #export (schedule millis-delay computation) + {#.doc "Runs an I/O computation on its own process (after a specified delay) and returns a Promise that will eventually host its result."} + (All [a] (-> Nat (IO a) (Promise a))) (let [!out (promise #.None)] - (exec ("lux process future" (io (io.run (resolve (io.run computation) - !out)))) + (exec ("lux process schedule" millis-delay + (io (io.run (resolve (io.run computation) + !out)))) !out))) -(def: #export (wait time) +(def: #export future + {#.doc "Runs an I/O computation on its own process and returns a Promise that will eventually host its result."} + (All [a] (-> (IO a) (Promise a))) + (schedule +0)) + +(def: #export (delay time-millis value) + {#.doc "Delivers a value after a certain period has passed."} + (All [a] (-> Nat a (Promise a))) + (schedule time-millis (io value))) + +(def: #export (wait time-millis) {#.doc "Returns a promise that will be resolved after the specified amount of milliseconds."} (-> Nat (Promise Top)) - (let [!out (: (Promise Top) (promise #.None))] - (exec ("lux process schedule" time (resolve [] !out)) - !out))) + (delay time-millis [])) -(def: #export (time-out time promise) +(def: #export (time-out time-millis promise) {#.doc "Wait for a promise to be resolved within the specified amount of milliseconds."} (All [a] (-> Nat (Promise a) (Promise (Maybe a)))) - (alt (wait time) promise)) - -(def: #export (delay time value) - {#.doc "Delivers a value after a certain period has passed."} - (All [a] (-> Nat a (Promise a))) - (:: Functor<Promise> map (function.const value) (wait time))) + (alt (wait time-millis) promise)) diff --git a/stdlib/source/lux/test.lux b/stdlib/source/lux/test.lux index e32bd2058..948923aeb 100644 --- a/stdlib/source/lux/test.lux +++ b/stdlib/source/lux/test.lux @@ -228,7 +228,7 @@ (` [(~ (code.text module-name)) (~ (code.symbol [module-name test])) (~ (code.text desc))])) tests) num-tests (list.size tests+) - groups (list.split-all promise.concurrency-level tests+)]] + groups (list.split-all promise.parallelism-level tests+)]] (wrap (list (` (: (~! (IO Top)) ((~! io) (exec ((~! do) (~! promise.Monad<Promise>) [(~' #let) [(~ g!total-successes) +0 |