aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/concurrency/promise.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/concurrency/promise.lux')
-rw-r--r--stdlib/source/lux/concurrency/promise.lux47
1 files changed, 4 insertions, 43 deletions
diff --git a/stdlib/source/lux/concurrency/promise.lux b/stdlib/source/lux/concurrency/promise.lux
index 3c10e785d..ef7efd923 100644
--- a/stdlib/source/lux/concurrency/promise.lux
+++ b/stdlib/source/lux/concurrency/promise.lux
@@ -12,47 +12,11 @@
[compiler]
(macro ["s" syntax #+ syntax: Syntax])
(concurrency [atom #+ Atom atom])
- host
))
-(jvm-import java.lang.Runtime
- (#static getRuntime [] Runtime)
- (availableProcessors [] int))
-
-(jvm-import java.lang.Runnable)
-
-(jvm-import java.lang.Thread
- (new [Runnable])
- (start [] void))
-
-(jvm-import java.util.concurrent.Executor
- (execute [Runnable] void))
-
-(jvm-import java.util.concurrent.TimeUnit
- (#enum MILLISECONDS))
-
-(jvm-import (java.util.concurrent.ScheduledFuture a))
-
-(jvm-import java.util.concurrent.ScheduledThreadPoolExecutor
- (new [int])
- (schedule [Runnable long TimeUnit] (ScheduledFuture Object)))
-
(def: #export concurrency-level
Nat
- (|> (Runtime.getRuntime [])
- (Runtime.availableProcessors [])
- int-to-nat))
-
-(def: executor
- ScheduledThreadPoolExecutor
- (ScheduledThreadPoolExecutor.new [(nat-to-int concurrency-level)]))
-
-(syntax: (runnable expr)
- (wrap (list (`' (object [java.lang.Runnable]
- []
- (java.lang.Runnable (run) void
- (exec (~ expr)
- [])))))))
+ (_lux_proc ["process" "concurrency-level"] []))
(type: (Promise-State a)
{#value (Maybe a)
@@ -218,18 +182,15 @@
{#;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))]
- (exec (Thread.start [] (Thread.new [(runnable (io;run (resolve (io;run computation)
- !out)))]))
+ (exec (_lux_proc ["process" "future"] [(io (io;run (resolve (io;run computation)
+ !out)))])
!out)))
(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)]
- (exec (ScheduledThreadPoolExecutor.schedule [(runnable (io;run (resolve [] !out)))
- (nat-to-int time)
- TimeUnit.MILLISECONDS]
- executor)
+ (exec (_lux_proc ["process" "schedule"] [time (resolve [] !out)])
!out)))
(def: #export (time-out time promise)