init commit
This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
(ns Process
|
||||
"Elixir Process module — BEAM process management.
|
||||
|
||||
In CljElixir: (Process/sleep 1000), (Process/send pid msg), etc.
|
||||
Provides utilities for working with BEAM processes (lightweight actors).")
|
||||
|
||||
(defn sleep
|
||||
"Sleeps the current process for `timeout` milliseconds or :infinity.
|
||||
(Process/sleep 1000) ;=> :ok (sleeps 1 second)
|
||||
(Process/sleep :infinity) ;=> blocks forever"
|
||||
[timeout])
|
||||
|
||||
(defn send
|
||||
"Sends `msg` to `dest` (pid, port, or registered name). Returns `msg`.
|
||||
(Process/send pid {:hello \"world\"})
|
||||
(Process/send pid msg [:noconnect]) ;=> with options"
|
||||
([dest msg])
|
||||
([dest msg opts]))
|
||||
|
||||
(defn spawn
|
||||
"Spawns a new process. Returns the PID.
|
||||
(Process/spawn (fn [] (IO/puts \"hi\")) [])
|
||||
(Process/spawn MyModule :my-func [arg1 arg2] [:link])"
|
||||
([fun opts])
|
||||
([module function args opts]))
|
||||
|
||||
(defn spawn-link
|
||||
"Spawns a linked process. If the child crashes, the parent crashes too.
|
||||
(Process/spawn-link (fn [] (IO/puts \"linked\")) [])"
|
||||
([fun opts])
|
||||
([module function args opts]))
|
||||
|
||||
(defn spawn-monitor
|
||||
"Spawns a monitored process. Returns {pid, ref}.
|
||||
(Process/spawn-monitor (fn [] (do-work)))"
|
||||
([fun])
|
||||
([module function args]))
|
||||
|
||||
(defn alive?
|
||||
"Returns true if the process identified by `pid` is alive.
|
||||
(Process/alive? pid) ;=> true"
|
||||
[pid])
|
||||
|
||||
(defn self
|
||||
"Returns the PID of the calling process.
|
||||
(Process/self) ;=> #PID<0.123.0>"
|
||||
[])
|
||||
|
||||
(defn whereis
|
||||
"Returns the PID registered under `name`, or nil.
|
||||
(Process/whereis :my-server) ;=> #PID<0.456.0>"
|
||||
[name])
|
||||
|
||||
(defn register
|
||||
"Registers a PID under the given atom `name`.
|
||||
(Process/register pid :my-server) ;=> true"
|
||||
[pid name])
|
||||
|
||||
(defn unregister
|
||||
"Unregisters the given `name`.
|
||||
(Process/unregister :my-server) ;=> true"
|
||||
[name])
|
||||
|
||||
(defn registered
|
||||
"Returns a list of all registered process names.
|
||||
(Process/registered) ;=> [:logger :code-server ...]"
|
||||
[])
|
||||
|
||||
(defn link
|
||||
"Creates a link between the calling process and `pid_or_port`.
|
||||
(Process/link pid)"
|
||||
[pid-or-port])
|
||||
|
||||
(defn unlink
|
||||
"Removes a link between the calling process and `pid_or_port`.
|
||||
(Process/unlink pid)"
|
||||
[pid-or-port])
|
||||
|
||||
(defn monitor
|
||||
"Starts monitoring `item`. Returns a reference.
|
||||
(Process/monitor :process pid)"
|
||||
([type item])
|
||||
([type item opts]))
|
||||
|
||||
(defn demonitor
|
||||
"Stops monitoring. The `ref` is from a previous `monitor` call.
|
||||
(Process/demonitor ref)
|
||||
(Process/demonitor ref [:flush])"
|
||||
([ref])
|
||||
([ref opts]))
|
||||
|
||||
(defn exit
|
||||
"Sends an exit signal to `pid`.
|
||||
(Process/exit pid :normal) ;=> normal shutdown
|
||||
(Process/exit pid :kill) ;=> forceful kill (untrappable)"
|
||||
[pid reason])
|
||||
|
||||
(defn flag
|
||||
"Sets process flags. Returns the old value.
|
||||
(Process/flag :trap-exit true) ;=> false (previous value)
|
||||
(Process/flag :priority :high)"
|
||||
([flag value])
|
||||
([pid flag value]))
|
||||
|
||||
(defn info
|
||||
"Returns info about a process.
|
||||
(Process/info pid) ;=> keyword list of process info
|
||||
(Process/info pid :message-queue-len) ;=> message queue length"
|
||||
([pid])
|
||||
([pid item]))
|
||||
|
||||
(defn list
|
||||
"Returns a list of all running process PIDs.
|
||||
(Process/list) ;=> [#PID<0.0.0> #PID<0.1.0> ...]"
|
||||
[])
|
||||
|
||||
(defn group-leader
|
||||
"Returns or sets the group leader.
|
||||
(Process/group-leader) ;=> #PID<0.64.0>
|
||||
(Process/group-leader pid gl)"
|
||||
([])
|
||||
([pid leader]))
|
||||
|
||||
(defn hibernate
|
||||
"Puts the process into hibernation (frees memory). Resumes in `fun`.
|
||||
(Process/hibernate Module :function [args])"
|
||||
[module function args])
|
||||
|
||||
(defn send-after
|
||||
"Sends `msg` to `dest` after `time` milliseconds. Returns a timer ref.
|
||||
(Process/send-after self :tick 1000)"
|
||||
([dest msg time])
|
||||
([dest msg time opts]))
|
||||
|
||||
(defn cancel-timer
|
||||
"Cancels a timer created by send-after."
|
||||
([timer-ref])
|
||||
([timer-ref opts]))
|
||||
|
||||
(defn read-timer
|
||||
"Returns the time remaining for a timer, or false."
|
||||
([timer-ref])
|
||||
([timer-ref opts]))
|
||||
|
||||
(defn put
|
||||
"Puts a key-value pair in the process dictionary. Returns old value or nil.
|
||||
(Process/put :my-key \"my value\") ;=> nil"
|
||||
[key value])
|
||||
|
||||
(defn get
|
||||
"Gets a value from the process dictionary.
|
||||
(Process/get :my-key) ;=> \"my value\"
|
||||
(Process/get :missing :default) ;=> :default"
|
||||
([key])
|
||||
([key default]))
|
||||
|
||||
(defn delete
|
||||
"Deletes a key from the process dictionary. Returns old value.
|
||||
(Process/delete :my-key) ;=> \"my value\""
|
||||
[key])
|
||||
|
||||
(defn get-keys
|
||||
"Returns all keys in the process dictionary (or keys with given value).
|
||||
(Process/get-keys) ;=> [:my-key ...]"
|
||||
([])
|
||||
([value]))
|
||||
Reference in New Issue
Block a user