Compatibility shim providing otplike.process API backed by loom-otp.
Key differences handled:
! function for sending (vs loom-otp's send)proc-fn, proc-defn macros (vs loom-otp's plain functions)async/await!/await!! implemented via vfuturereceive!! variant (blocking) is same as receive! in virtual threadsThis namespace does NOT modify loom-otp internals.
Compatibility shim providing otplike.process API backed by loom-otp.
Key differences handled:
- `!` function for sending (vs loom-otp's `send`)
- `proc-fn`, `proc-defn` macros (vs loom-otp's plain functions)
- `async`/`await!`/`await!!` implemented via vfuture
- Tuple returns [:ok pid] vs map {:ok pid}
- `receive!!` variant (blocking) is same as receive! in virtual threads
This namespace does NOT modify loom-otp internals.(! dest message)Send a message to dest (pid or registered name). Returns true if sent, false if not.
Send a message to dest (pid or registered name). Returns true if sent, false if not.
(alive?)(alive? pid)Check if process is alive.
Check if process is alive.
(async & body)Execute body immediately and capture the result or exception. Returns an Async value that can be awaited.
The body runs synchronously on the calling thread. This maintains the single-thread-per-process model and allows async code to access the process mailbox.
NOTE: InterruptedException is NOT caught during execution - it needs to propagate to the spawn handler which checks the exit-reason set by exit signals.
Execute body immediately and capture the result or exception. Returns an Async value that can be awaited. The body runs synchronously on the calling thread. This maintains the single-thread-per-process model and allows async code to access the process mailbox. NOTE: InterruptedException is NOT caught during execution - it needs to propagate to the spawn handler which checks the exit-reason set by exit signals.
(async-value value)Wrap a value as an already-completed async.
Wrap a value as an already-completed async.
(async? x)Returns true if x is an async value.
Returns true if x is an async value.
(await! x)Wait for async value and return result. Parks/blocks if needed.
Wait for async value and return result. Parks/blocks if needed.
(await!! x)Same as await! - blocks. In virtual threads there's no difference. Throws IllegalArgumentException if x is not an async value.
Same as await! - blocks. In virtual threads there's no difference. Throws IllegalArgumentException if x is not an async value.
(await?! x)If x is async, await it. Otherwise return x.
If x is async, await it. Otherwise return x.
(demonitor mref)(demonitor mref {:keys [flush]})Remove a monitor. With {:flush true}, removes pending DOWN messages. Throws when called not in process context, or mref is not a ref.
Remove a monitor. With {:flush true}, removes pending DOWN messages.
Throws when called not in process context, or mref is not a ref.(ex->reason e)Convert exception to exit reason. Uses util/stack-trace for otplike-compatible exception format. InterruptedException is converted to :killed.
Convert exception to exit reason. Uses util/stack-trace for otplike-compatible exception format. InterruptedException is converted to :killed.
(ex-catch expr)Execute expr, return result or [:EXIT reason] on exception.
Execute expr, return result or [:EXIT reason] on exception.
(exit reason)(exit pid reason)Exit with reason, or send exit signal to pid with reason. Returns true if process is/was alive, false if already terminated.
Exit with reason, or send exit signal to pid with reason. Returns true if process is/was alive, false if already terminated.
(flag flag-name value)Set a process flag. Returns the old value. Currently supports :trap-exit.
Set a process flag. Returns the old value. Currently supports :trap-exit.
(link pid)Create a bidirectional link between calling process and pid. Must be called from within a process context. If pid is terminated, sends [:EXIT pid :noproc] to self if trapping exits, otherwise causes self to exit.
Create a bidirectional link between calling process and pid. Must be called from within a process context. If pid is terminated, sends [:EXIT pid :noproc] to self if trapping exits, otherwise causes self to exit.
(map-async f async-val)Apply f to the eventual value of async-val. Creates a new Async that will apply f after the original transformations. The new Async shares the same result atom.
Apply f to the eventual value of async-val. Creates a new Async that will apply f after the original transformations. The new Async shares the same result atom.
(monitor pid-or-name)Monitor a process. Returns a reference.
Monitor a process. Returns a reference.
(pid->str pid)Convert pid to string representation.
Convert pid to string representation.
(pid? x)Returns true if x is a process identifier.
Returns true if x is a process identifier.
(proc-defn fname doc-string? args & body)Define a process function. Same as (def name (proc-fn ...))
Define a process function. Same as (def name (proc-fn ...))
(proc-defn- fname & more)Same as proc-defn but private.
Same as proc-defn but private.
(proc-fn name-or-args & more)Create a process function. Returns a function suitable for spawn.
Usage: (proc-fn [x y] (+ x y)) (proc-fn my-name [x] (do-something x))
In otplike this creates a TProcFn for go blocks. In loom-otp this creates a regular function.
Create a process function. Returns a function suitable for spawn. Usage: (proc-fn [x y] (+ x y)) (proc-fn my-name [x] (do-something x)) In otplike this creates a TProcFn for go blocks. In loom-otp this creates a regular function.
(process-info pid)(process-info pid items)Get information about a process. Throws if pid is not a pid, or specified info-key doesn't exist.
Get information about a process. Throws if pid is not a pid, or specified info-key doesn't exist.
(processes)Return list of all process pids.
Return list of all process pids.
(receive! & clauses)Receive a message with pattern matching. Supports (after timeout body) clause.
Receive a message with pattern matching. Supports (after timeout body) clause.
(receive!! & clauses)Same as receive! - in virtual threads blocking is the same as parking.
Same as receive! - in virtual threads blocking is the same as parking.
(ref? x)Returns true if x is a reference.
Returns true if x is a reference.
(registered)Returns a set of all registered names.
Returns a set of all registered names.
(resolve-pid pid-or-name)Resolve pid-or-name to a pid. Returns nil if not found.
Resolve pid-or-name to a pid. Returns nil if not found.
(selective-receive! & clauses)Selective receive with pattern matching. Scans mailbox for first matching message.
Selective receive with pattern matching. Scans mailbox for first matching message.
(self)Returns the process identifier of the calling process.
Returns the process identifier of the calling process.
(spawn proc-func)(spawn proc-func args)Spawn a process running (proc-func & args).
Spawn a process running (proc-func & args).
(spawn-link proc-func)(spawn-link proc-func args)Spawn a process linked to the calling process.
Spawn a process linked to the calling process.
(spawn-opt proc-func opts)(spawn-opt proc-func args opts)Spawn a process with options. proc-func is a function (not proc-fn). Options: :flags {:trap-exit true}, :link true, :register name
Spawn a process with options.
proc-func is a function (not proc-fn).
Options: :flags {:trap-exit true}, :link true, :register name(trace pred handler)Set up tracing with predicate and handler.
Set up tracing with predicate and handler.
(unlink pid)Remove link between calling process and pid. Must be called from within a process context.
Remove link between calling process and pid. Must be called from within a process context.
(whereis name)Returns the pid registered under name, or nil.
Returns the pid registered under name, or nil.
(with-async [binding async-expr] & body)Transform async value with body. Body receives the resolved value.
Transform async value with body. Body receives the resolved value.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |