aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2018-05-08 22:30:03 -0400
committerEduardo Julian2018-05-08 22:30:03 -0400
commit8c90251c12a4d0d4cc191bfb273bb5eb51bb0356 (patch)
tree5964bba6bedd134c244bc322df4cced3419ca957 /stdlib
parentca9541c0c10d4e6aa94055ecfb47301ed7292828 (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')
-rw-r--r--stdlib/source/lux/concurrency/promise.lux40
-rw-r--r--stdlib/source/lux/test.lux2
-rw-r--r--stdlib/test/test/lux/concurrency/stm.lux4
3 files changed, 25 insertions, 21 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
diff --git a/stdlib/test/test/lux/concurrency/stm.lux b/stdlib/test/test/lux/concurrency/stm.lux
index 58c0d7ef3..bf562c0fa 100644
--- a/stdlib/test/test/lux/concurrency/stm.lux
+++ b/stdlib/test/test/lux/concurrency/stm.lux
@@ -63,8 +63,8 @@
(map (function (_ _)
(M.map @ (function (_ _) (&.commit (&.update i/inc _concurrency-var)))
(list.i/range 1 iterations/processes)))
- (list.i/range 1 (nat-to-int promise.concurrency-level))))
+ (list.i/range 1 (nat-to-int promise.parallelism-level))))
last-val (&.commit (&.read _concurrency-var))]
(assert "Can modify STM vars concurrently from multiple threads."
- (i/= (i/* iterations/processes (nat-to-int promise.concurrency-level))
+ (i/= (i/* iterations/processes (nat-to-int promise.parallelism-level))
last-val)))))))