aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/control/concurrency/thread.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/control/concurrency/thread.lux118
1 files changed, 48 insertions, 70 deletions
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))