aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/control/concurrency/process.lux
diff options
context:
space:
mode:
authorEduardo Julian2020-06-28 21:32:43 -0400
committerEduardo Julian2020-06-28 21:32:43 -0400
commitb1606a5efcba32abe722759dbfca02586ff2179a (patch)
tree74d306f16757eaf8639304f6db46137b49a6076d /stdlib/source/lux/control/concurrency/process.lux
parentec29b735396a656862ab9dcdde3627e234c938b0 (diff)
The "for" macro can now work directly with definitions. No text literals necessary.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/control/concurrency/process.lux238
1 files changed, 119 insertions, 119 deletions
diff --git a/stdlib/source/lux/control/concurrency/process.lux b/stdlib/source/lux/control/concurrency/process.lux
index 2060233e3..4d6cc8cb3 100644
--- a/stdlib/source/lux/control/concurrency/process.lux
+++ b/stdlib/source/lux/control/concurrency/process.lux
@@ -15,143 +15,143 @@
[//
["." atom (#+ Atom)]])
-(`` (for {(~~ (static @.old))
- (as-is (host.import: #long java/lang/Object)
+(for {@.old
+ (as-is (host.import: #long java/lang/Object)
- (host.import: #long java/lang/Runtime
- (#static getRuntime [] java/lang/Runtime)
- (availableProcessors [] int))
+ (host.import: #long java/lang/Runtime
+ (#static getRuntime [] java/lang/Runtime)
+ (availableProcessors [] int))
- (host.import: #long java/lang/Runnable)
+ (host.import: #long java/lang/Runnable)
- (host.import: #long java/util/concurrent/TimeUnit
- (#enum MILLISECONDS))
-
- (host.import: #long java/util/concurrent/Executor
- (execute [java/lang/Runnable] #io void))
+ (host.import: #long java/util/concurrent/TimeUnit
+ (#enum MILLISECONDS))
+
+ (host.import: #long java/util/concurrent/Executor
+ (execute [java/lang/Runnable] #io void))
- (host.import: #long (java/util/concurrent/ScheduledFuture a))
+ (host.import: #long (java/util/concurrent/ScheduledFuture a))
- (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))))
+ (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 (host.import: #long java/lang/Object)
+ @.jvm
+ (as-is (host.import: #long java/lang/Object)
- (host.import: #long java/lang/Runtime
- (#static getRuntime [] java/lang/Runtime)
- (availableProcessors [] int))
+ (host.import: #long java/lang/Runtime
+ (#static getRuntime [] java/lang/Runtime)
+ (availableProcessors [] int))
- (host.import: #long java/lang/Runnable)
+ (host.import: #long java/lang/Runnable)
- (host.import: #long java/util/concurrent/TimeUnit
- (#enum MILLISECONDS))
-
- (host.import: #long java/util/concurrent/Executor
- (execute [java/lang/Runnable] #io void))
+ (host.import: #long java/util/concurrent/TimeUnit
+ (#enum MILLISECONDS))
+
+ (host.import: #long java/util/concurrent/Executor
+ (execute [java/lang/Runnable] #io void))
- (host.import: #long (java/util/concurrent/ScheduledFuture a))
+ (host.import: #long (java/util/concurrent/ScheduledFuture a))
- (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))))}
-
- ## Default
- (type: Process
- {#creation Nat
- #delay Nat
- #action (IO Any)})
- ))
+ (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))))}
+
+ ## Default
+ (type: Process
+ {#creation Nat
+ #delay Nat
+ #action (IO Any)})
+ )
(def: #export parallelism
Nat
- (`` (for {(~~ (static @.old))
- (|> (java/lang/Runtime::getRuntime)
- (java/lang/Runtime::availableProcessors)
- .nat)
-
- (~~ (static @.jvm))
- (|> (java/lang/Runtime::getRuntime)
- (java/lang/Runtime::availableProcessors)
- .nat)}
-
- ## Default
- 1)))
+ (for {@.old
+ (|> (java/lang/Runtime::getRuntime)
+ (java/lang/Runtime::availableProcessors)
+ .nat)
+
+ @.jvm
+ (|> (java/lang/Runtime::getRuntime)
+ (java/lang/Runtime::availableProcessors)
+ .nat)}
+
+ ## Default
+ 1))
(def: runner
- (`` (for {(~~ (static @.old))
- (java/util/concurrent/ScheduledThreadPoolExecutor::new (.int ..parallelism))
+ (for {@.old
+ (java/util/concurrent/ScheduledThreadPoolExecutor::new (.int ..parallelism))
- (~~ (static @.jvm))
- (java/util/concurrent/ScheduledThreadPoolExecutor::new (.int ..parallelism))}
-
- ## Default
- (: (Atom (List Process))
- (atom.atom (list))))))
+ @.jvm
+ (java/util/concurrent/ScheduledThreadPoolExecutor::new (.int ..parallelism))}
+
+ ## Default
+ (: (Atom (List Process))
+ (atom.atom (list)))))
(def: #export (schedule milli-seconds action)
(-> Nat (IO Any) (IO Any))
- (`` (for {(~~ (static @.old))
- (let [runnable (host.object [] [java/lang/Runnable]
- []
- (java/lang/Runnable [] (run self) void
- (io.run action)))]
- (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
- runner)))
-
- (~~ (static @.jvm))
- (let [runnable (host.object [] [java/lang/Runnable]
- []
- (java/lang/Runnable [] (run self) void
- (io.run action)))]
- (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
- runner)))}
-
- ## Default
- (do io.monad
- [_ (atom.update (|>> (#.Cons {#creation (.nat ("lux io current-time"))
- #delay milli-seconds
- #action action}))
- runner)]
- (wrap [])))))
-
-(`` (for {(~~ (static @.old))
- (as-is)
-
- (~~ (static @.jvm))
- (as-is)}
-
- ## Default
- (as-is (exception: #export cannot-continue-running-processes)
-
- (def: #export run!
- (IO Any)
- (loop [_ []]
- (do {@ io.monad}
- [processes (atom.read runner)]
- (case processes
- ## And... we're done!
- #.Nil
- (wrap [])
-
- _
+ (for {@.old
+ (let [runnable (host.object [] [java/lang/Runnable]
+ []
+ (java/lang/Runnable [] (run self) void
+ (io.run action)))]
+ (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
+ runner)))
+
+ @.jvm
+ (let [runnable (host.object [] [java/lang/Runnable]
+ []
+ (java/lang/Runnable [] (run self) void
+ (io.run action)))]
+ (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
+ runner)))}
+
+ ## Default
+ (do io.monad
+ [_ (atom.update (|>> (#.Cons {#creation (.nat ("lux io current-time"))
+ #delay milli-seconds
+ #action action}))
+ runner)]
+ (wrap []))))
+
+(for {@.old
+ (as-is)
+
+ @.jvm
+ (as-is)}
+
+ ## Default
+ (as-is (exception: #export cannot-continue-running-processes)
+
+ (def: #export run!
+ (IO Any)
+ (loop [_ []]
+ (do {@ io.monad}
+ [processes (atom.read runner)]
+ (case processes
+ ## And... we're done!
+ #.Nil
+ (wrap [])
+
+ _
+ (do @
+ [#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)]
+ (if swapped?
(do @
- [#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)]
- (if swapped?
- (do @
- [_ (monad.map @ (get@ #action) ready)]
- (wrap []))
- (error! (ex.construct cannot-continue-running-processes []))))
- ))))
- )))
+ [_ (monad.map @ (get@ #action) ready)]
+ (wrap []))
+ (error! (ex.construct cannot-continue-running-processes []))))
+ ))))
+ ))