diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/control/concurrency/thread.lux | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/stdlib/source/lux/control/concurrency/thread.lux b/stdlib/source/lux/control/concurrency/thread.lux index 10ec17815..8bdd2b9c9 100644 --- a/stdlib/source/lux/control/concurrency/thread.lux +++ b/stdlib/source/lux/control/concurrency/thread.lux @@ -15,7 +15,7 @@ [// ["." atom (#+ Atom)]]) -(with-expansions [<jvm> (as-is (host.import: java/lang/Object) +(with_expansions [<jvm> (as_is (host.import: java/lang/Object) (host.import: java/lang/Runtime ["#::." @@ -38,11 +38,11 @@ ["#::." (new [int]) (schedule [java/lang/Runnable long java/util/concurrent/TimeUnit] #io (java/util/concurrent/ScheduledFuture java/lang/Object))]))] - (for {@.old (as-is <jvm>) - @.jvm (as-is <jvm>) + (for {@.old (as_is <jvm>) + @.jvm (as_is <jvm>) @.js - (as-is (host.import: (setTimeout [host.Function host.Number] #io Any)))} + (as_is (host.import: (setTimeout [host.Function host.Number] #io Any)))} ## Default (type: Thread @@ -53,7 +53,7 @@ (def: #export parallelism Nat - (with-expansions [<jvm> (|> (java/lang/Runtime::getRuntime) + (with_expansions [<jvm> (|> (java/lang/Runtime::getRuntime) (java/lang/Runtime::availableProcessors) .nat)] (for {@.old <jvm> @@ -62,30 +62,30 @@ ## Default 1))) -(with-expansions [<jvm> (as-is (def: runner +(with_expansions [<jvm> (as_is (def: runner java/util/concurrent/ScheduledThreadPoolExecutor (java/util/concurrent/ScheduledThreadPoolExecutor::new (.int ..parallelism))))] (for {@.old <jvm> @.jvm <jvm> @.js - (as-is)} + (as_is)} ## Default (def: runner (Atom (List Thread)) (atom.atom (list))))) -(def: #export (schedule milli-seconds action) +(def: #export (schedule milli_seconds action) (-> Nat (IO Any) (IO Any)) (for {@.old (let [runnable (host.object [] [java/lang/Runnable] [] (java/lang/Runnable [] (run self) void (io.run action)))] - (case milli-seconds + (case milli_seconds 0 (java/util/concurrent/Executor::execute runnable runner) - _ (java/util/concurrent/ScheduledThreadPoolExecutor::schedule runnable (.int milli-seconds) java/util/concurrent/TimeUnit::MILLISECONDS + _ (java/util/concurrent/ScheduledThreadPoolExecutor::schedule runnable (.int milli_seconds) java/util/concurrent/TimeUnit::MILLISECONDS runner))) @.jvm @@ -93,34 +93,34 @@ [] (java/lang/Runnable [] (run self) void (io.run action)))] - (case milli-seconds + (case milli_seconds 0 (java/util/concurrent/Executor::execute runnable runner) - _ (java/util/concurrent/ScheduledThreadPoolExecutor::schedule runnable (.int milli-seconds) java/util/concurrent/TimeUnit::MILLISECONDS + _ (java/util/concurrent/ScheduledThreadPoolExecutor::schedule runnable (.int milli_seconds) java/util/concurrent/TimeUnit::MILLISECONDS runner))) @.js (..setTimeout [(host.closure [] (io.run action)) - (n.frac milli-seconds)])} + (n.frac milli_seconds)])} ## Default (do io.monad [_ (atom.update (|>> (#.Cons {#creation (.nat ("lux io current-time")) - #delay milli-seconds + #delay milli_seconds #action action})) ..runner)] (wrap [])))) (for {@.old - (as-is) + (as_is) @.jvm - (as-is) + (as_is) @.js - (as-is)} + (as_is)} ## Default - (as-is (exception: #export cannot-continue-running-threads) + (as_is (exception: #export cannot_continue_running_threads) (def: #export (run! _) (-> Any (IO Any)) @@ -139,11 +139,11 @@ (n.+ (get@ #delay thread)) (n.<= now))) threads)] - swapped? (atom.compare-and-swap threads pending ..runner)] + swapped? (atom.compare_and_swap threads pending ..runner)] (if swapped? (do ! [_ (monad.map ! (get@ #action) ready)] (run! [])) - (error! (ex.construct ..cannot-continue-running-threads [])))) + (error! (ex.construct ..cannot_continue_running_threads [])))) ))) )) |