diff options
author | Eduardo Julian | 2019-06-15 19:45:32 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-06-15 19:45:32 -0400 |
commit | 0cc98bbe9cae3fd9fc50d8c78c1deaba7e557531 (patch) | |
tree | 4439100c5f036870282b6c93ac45e3731bcdf6fd /stdlib/source/lux/control/concurrency/process.lux | |
parent | 7ee04017ee2ef5376c566b00750fd521c0ecac42 (diff) |
Array machinery for the JavaScript compiler.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/control/concurrency/process.lux | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/stdlib/source/lux/control/concurrency/process.lux b/stdlib/source/lux/control/concurrency/process.lux index fc5ad2050..7cb569ee9 100644 --- a/stdlib/source/lux/control/concurrency/process.lux +++ b/stdlib/source/lux/control/concurrency/process.lux @@ -1,7 +1,7 @@ (.module: [lux #* ["@" target] - ["." host (#+ import: object)] + ["." host] [abstract ["." monad (#+ do)]] [control @@ -14,44 +14,44 @@ ["." atom (#+ Atom)]]) (`` (for {(~~ (static @.old)) - (as-is (import: #long java/lang/Object) + (as-is (host.import: #long java/lang/Object) - (import: #long java/lang/Runtime + (host.import: #long java/lang/Runtime (#static getRuntime [] java/lang/Runtime) (availableProcessors [] int)) - (import: #long java/lang/Runnable) + (host.import: #long java/lang/Runnable) - (import: #long java/util/concurrent/TimeUnit + (host.import: #long java/util/concurrent/TimeUnit (#enum MILLISECONDS)) - (import: #long java/util/concurrent/Executor + (host.import: #long java/util/concurrent/Executor (execute [java/lang/Runnable] #io void)) - (import: #long (java/util/concurrent/ScheduledFuture a)) + (host.import: #long (java/util/concurrent/ScheduledFuture a)) - (import: #long java/util/concurrent/ScheduledThreadPoolExecutor + (host.import: #long java/util/concurrent/ScheduledThreadPoolExecutor (new [int]) (schedule [java/lang/Runnable long java/util/concurrent/TimeUnit] #io (java/util/concurrent/ScheduledFuture java/lang/Object)))) (~~ (static @.jvm)) - (as-is (import: #long java/lang/Object) + (as-is (host.import: #long java/lang/Object) - (import: #long java/lang/Runtime + (host.import: #long java/lang/Runtime (#static getRuntime [] java/lang/Runtime) (availableProcessors [] int)) - (import: #long java/lang/Runnable) + (host.import: #long java/lang/Runnable) - (import: #long java/util/concurrent/TimeUnit + (host.import: #long java/util/concurrent/TimeUnit (#enum MILLISECONDS)) - (import: #long java/util/concurrent/Executor + (host.import: #long java/util/concurrent/Executor (execute [java/lang/Runnable] #io void)) - (import: #long (java/util/concurrent/ScheduledFuture a)) + (host.import: #long (java/util/concurrent/ScheduledFuture a)) - (import: #long java/util/concurrent/ScheduledThreadPoolExecutor + (host.import: #long java/util/concurrent/ScheduledThreadPoolExecutor (new [int]) (schedule [java/lang/Runnable long java/util/concurrent/TimeUnit] #io (java/util/concurrent/ScheduledFuture java/lang/Object))))} @@ -91,7 +91,7 @@ (def: #export (schedule milli-seconds action) (-> Nat (IO Any) (IO Any)) (`` (for {(~~ (static @.old)) - (let [runnable (object [] [java/lang/Runnable] + (let [runnable (host.object [] [java/lang/Runnable] [] (java/lang/Runnable [] (run self) void (io.run action)))] @@ -101,7 +101,7 @@ runner))) (~~ (static @.jvm)) - (let [runnable (object [] [java/lang/Runnable] + (let [runnable (host.object [] [java/lang/Runnable] [] (java/lang/Runnable [] (run self) void (io.run action)))] @@ -111,10 +111,12 @@ runner)))} ## Default - (atom.update (|>> (#.Cons {#creation ("lux io current-time") - #delay milli-seconds - #action action})) - runner)))) + (do io.monad + [_ (atom.update (|>> (#.Cons {#creation (.nat ("lux io current-time")) + #delay milli-seconds + #action action})) + runner)] + (wrap []))))) (`` (for {(~~ (static @.old)) (as-is) @@ -137,15 +139,17 @@ _ (do @ - [#let [now ("lux io current-time") + [#let [now (.nat ("lux io current-time")) [ready pending] (list.partition (function (_ process) (|> (get@ #creation process) (n/+ (get@ #delay process)) (n/<= now))) processes)] - swapped? (atom.compare-and-swap! processes pending runner)] + swapped? (atom.compare-and-swap processes pending runner)] (if swapped? - (monad.seq @ ready) + (do @ + [_ (monad.map @ (get@ #action) ready)] + (wrap [])) (error! (ex.construct cannot-continue-running-processes [])))) )))) ))) |