diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/control/concurrency/atom.lux | 22 | ||||
-rw-r--r-- | stdlib/source/lux/control/concurrency/thread.lux | 118 |
2 files changed, 57 insertions, 83 deletions
diff --git a/stdlib/source/lux/control/concurrency/atom.lux b/stdlib/source/lux/control/concurrency/atom.lux index 54be96d76..04517cc3e 100644 --- a/stdlib/source/lux/control/concurrency/atom.lux +++ b/stdlib/source/lux/control/concurrency/atom.lux @@ -13,19 +13,15 @@ [type abstract]]) -(for {@.old - (host.import: (java/util/concurrent/atomic/AtomicReference a) - (new [a]) - (get [] a) - (compareAndSet [a a] boolean)) - - @.jvm - (host.import: (java/util/concurrent/atomic/AtomicReference a) - (new [a]) - (get [] a) - (compareAndSet [a a] boolean))} - - (as-is)) +(with-expansions [<jvm> (as-is (host.import: (java/util/concurrent/atomic/AtomicReference a) + ["#::." + (new [a]) + (get [] a) + (compareAndSet [a a] boolean)]))] + (for {@.old <jvm> + @.jvm <jvm>} + + (as-is))) (abstract: #export (Atom a) (for {@.old diff --git a/stdlib/source/lux/control/concurrency/thread.lux b/stdlib/source/lux/control/concurrency/thread.lux index 55b635672..10ec17815 100644 --- a/stdlib/source/lux/control/concurrency/thread.lux +++ b/stdlib/source/lux/control/concurrency/thread.lux @@ -15,88 +15,66 @@ [// ["." atom (#+ Atom)]]) -(for {@.old - (as-is (host.import: java/lang/Object) - - (host.import: java/lang/Runtime - (#static getRuntime [] java/lang/Runtime) - (availableProcessors [] int)) - - (host.import: java/lang/Runnable) - - (host.import: java/util/concurrent/TimeUnit - (#enum MILLISECONDS)) - - (host.import: java/util/concurrent/Executor - (execute [java/lang/Runnable] #io void)) +(with-expansions [<jvm> (as-is (host.import: java/lang/Object) - (host.import: (java/util/concurrent/ScheduledFuture a)) - - (host.import: java/util/concurrent/ScheduledThreadPoolExecutor - (new [int]) - (schedule [java/lang/Runnable long java/util/concurrent/TimeUnit] #io (java/util/concurrent/ScheduledFuture java/lang/Object)))) - - @.jvm - (as-is (host.import: java/lang/Object) + (host.import: java/lang/Runtime + ["#::." + (#static getRuntime [] java/lang/Runtime) + (availableProcessors [] int)]) - (host.import: java/lang/Runtime - (#static getRuntime [] java/lang/Runtime) - (availableProcessors [] int)) + (host.import: java/lang/Runnable) - (host.import: java/lang/Runnable) + (host.import: java/util/concurrent/TimeUnit + ["#::." + (#enum MILLISECONDS)]) + + (host.import: java/util/concurrent/Executor + ["#::." + (execute [java/lang/Runnable] #io void)]) - (host.import: java/util/concurrent/TimeUnit - (#enum MILLISECONDS)) - - (host.import: java/util/concurrent/Executor - (execute [java/lang/Runnable] #io void)) + (host.import: (java/util/concurrent/ScheduledFuture a)) - (host.import: (java/util/concurrent/ScheduledFuture a)) + (host.import: java/util/concurrent/ScheduledThreadPoolExecutor + ["#::." + (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>) - (host.import: java/util/concurrent/ScheduledThreadPoolExecutor - (new [int]) - (schedule [java/lang/Runnable long java/util/concurrent/TimeUnit] #io (java/util/concurrent/ScheduledFuture java/lang/Object)))) - - @.js - (as-is (host.import: (setTimeout [host.Function host.Number] #io Any)))} - - ## Default - (type: Thread - {#creation Nat - #delay Nat - #action (IO Any)}) - ) + @.js + (as-is (host.import: (setTimeout [host.Function host.Number] #io Any)))} + + ## Default + (type: Thread + {#creation Nat + #delay Nat + #action (IO Any)}) + )) (def: #export parallelism Nat - (for {@.old - (|> (java/lang/Runtime::getRuntime) - (java/lang/Runtime::availableProcessors) - .nat) + (with-expansions [<jvm> (|> (java/lang/Runtime::getRuntime) + (java/lang/Runtime::availableProcessors) + .nat)] + (for {@.old <jvm> + @.jvm <jvm>} + + ## Default + 1))) + +(with-expansions [<jvm> (as-is (def: runner + java/util/concurrent/ScheduledThreadPoolExecutor + (java/util/concurrent/ScheduledThreadPoolExecutor::new (.int ..parallelism))))] + (for {@.old <jvm> + @.jvm <jvm> - @.jvm - (|> (java/lang/Runtime::getRuntime) - (java/lang/Runtime::availableProcessors) - .nat)} + @.js + (as-is)} ## Default - 1)) - -(for {@.old - (def: runner - (java/util/concurrent/ScheduledThreadPoolExecutor::new (.int ..parallelism))) - - @.jvm - (def: runner - (java/util/concurrent/ScheduledThreadPoolExecutor::new (.int ..parallelism))) - - @.js - (as-is)} - - ## Default - (def: runner - (Atom (List Thread)) - (atom.atom (list)))) + (def: runner + (Atom (List Thread)) + (atom.atom (list))))) (def: #export (schedule milli-seconds action) (-> Nat (IO Any) (IO Any)) |