Concurrency gate — bounded-permit execution with timeout.
A gate wraps a java.util.concurrent.Semaphore with:
Three ways to use:
with-gate — bracket macro, throws on timeoutgate-run — function, returns Resultderef-gate — gated deref for promises/futures with timeoutAlso satisfies hive-weave.budget/IBudgetGate so consumers can depend on the unit-agnostic protocol regardless of whether the underlying gate is slot-permit-based (this ns) or byte-cost-based (hive-weave.budget).
Usage: (def db-read (gate {:permits 4 :timeout-ms 15000 :name "db-read"}))
(with-gate db-read (query-database ...)) (deref-gate db-read (chroma/query coll embedding))
Concurrency gate — bounded-permit execution with timeout.
A gate wraps a java.util.concurrent.Semaphore with:
- Timeout-aware permit acquisition
- Result integration (gate-run returns ok/err instead of throwing)
- Diagnostics (available permits, queue length)
Three ways to use:
1. `with-gate` — bracket macro, throws on timeout
2. `gate-run` — function, returns Result
3. `deref-gate` — gated deref for promises/futures with timeout
Also satisfies hive-weave.budget/IBudgetGate so consumers can depend on
the unit-agnostic protocol regardless of whether the underlying gate is
slot-permit-based (this ns) or byte-cost-based (hive-weave.budget).
Usage:
(def db-read (gate {:permits 4 :timeout-ms 15000 :name "db-read"}))
(with-gate db-read (query-database ...))
(deref-gate db-read (chroma/query coll embedding))(deref-gate g derefable)(deref-gate g derefable timeout-ms)Deref a promise/future under the gate's permit with timeout.
Replaces bare @(chroma/query ...) with bounded concurrency + timeout.
Deref a promise/future under the gate's permit with timeout. Replaces bare `@(chroma/query ...)` with bounded concurrency + timeout.
(gate {:keys [permits timeout-ms name fair?]
:or {permits 1 timeout-ms 30000 name "gate" fair? true}})Create a concurrency gate.
Options: :permits — max concurrent executions (default 1, i.e. serialized) :timeout-ms — max wait for permit acquisition (default 30000) :name — diagnostic name (default "gate") :fair? — FIFO ordering for waiters (default true)
Create a concurrency gate. Options: :permits — max concurrent executions (default 1, i.e. serialized) :timeout-ms — max wait for permit acquisition (default 30000) :name — diagnostic name (default "gate") :fair? — FIFO ordering for waiters (default true)
(gate-run g f)Execute f under the gate's permit. Returns Result.
On success: (ok <return-value>) On timeout: (err :gate/timeout {...}) On error: (err :gate/execution-failed {...})
Execute f under the gate's permit. Returns Result.
On success: (ok <return-value>)
On timeout: (err :gate/timeout {...})
On error: (err :gate/execution-failed {...})(gate-run! g f)Execute f under the gate's permit. Throws on timeout.
Execute f under the gate's permit. Throws on timeout.
(gate-stats g)Current gate state for diagnostics.
Current gate state for diagnostics.
(with-gate g & body)Execute body under gate permit. Throws on timeout.
(with-gate db-read (query-database ...))
Execute body under gate permit. Throws on timeout. (with-gate db-read (query-database ...))
(with-gate-result g & body)Execute body under gate permit. Returns Result.
(with-gate-result db-write (insert-record! ...))
Execute body under gate permit. Returns Result. (with-gate-result db-write (insert-record! ...))
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 |