Bounded parallel execution — safe alternatives to pmap and raw futures.
bounded-pmap — pmap with concurrency limit + per-item timeoutfork-join — concurrent futures with collective timeout budgetfan-out — fire N tasks, collect results with timeoutUnlike pmap, these primitives:
Bounded parallel execution — safe alternatives to pmap and raw futures. - `bounded-pmap` — pmap with concurrency limit + per-item timeout - `fork-join` — concurrent futures with collective timeout budget - `fan-out` — fire N tasks, collect results with timeout Unlike `pmap`, these primitives: 1. Bound concurrency (no unbounded thread creation) 2. Have timeouts (no indefinite hangs) 3. Return fallback values on timeout (graceful degradation)
(bounded-pmap {:keys [concurrency timeout-ms fallback]
:or {concurrency 4 timeout-ms 10000 fallback nil}}
f
coll)Like pmap but with bounded concurrency and per-item timeout.
Options: :concurrency — max parallel workers (default 4) :timeout-ms — per-item timeout in ms (default 10000) :fallback — value for timed-out/failed items (default nil)
(bounded-pmap {:concurrency 3 :timeout-ms 5000} fetch-entry-preview entry-ids) ;; => [result1 result2 nil result4 ...] (nil = timed out)
Like pmap but with bounded concurrency and per-item timeout.
Options:
:concurrency — max parallel workers (default 4)
:timeout-ms — per-item timeout in ms (default 10000)
:fallback — value for timed-out/failed items (default nil)
(bounded-pmap {:concurrency 3 :timeout-ms 5000}
fetch-entry-preview entry-ids)
;; => [result1 result2 nil result4 ...] (nil = timed out)(fan-out opts f coll)Apply f to each item in coll concurrently, collect results with timeout. Like bounded-pmap but returns a Result for the whole batch.
(fan-out {:concurrency 4 :timeout-ms 5000} fetch-preview ids) ;; => (ok [r1 r2 r3 ...]) — all completed ;; => (ok [r1 nil r3 ...]) — some timed out (nils)
Always returns (ok ...) — individual failures become nil/fallback.
Apply f to each item in coll concurrently, collect results with timeout.
Like bounded-pmap but returns a Result for the whole batch.
(fan-out {:concurrency 4 :timeout-ms 5000} fetch-preview ids)
;; => (ok [r1 r2 r3 ...]) — all completed
;; => (ok [r1 nil r3 ...]) — some timed out (nils)
Always returns (ok ...) — individual failures become nil/fallback.(fork-join {:keys [budget-ms] :or {budget-ms 15000}} & tasks)Execute named tasks concurrently with a collective timeout budget. Each task is a [key thunk] or [key thunk fallback] triple. Returns a map of {key result} — timed-out tasks get their fallback.
(fork-join {:budget-ms 15000} [:tags #(query-tags candidate-tags) {}] [:kg #(expand-via-kg vanilla-ids) #{}]) ;; => {:tags {...} :kg #{...}}
Options: :budget-ms — total time budget for all tasks (default 15000)
Execute named tasks concurrently with a collective timeout budget.
Each task is a [key thunk] or [key thunk fallback] triple.
Returns a map of {key result} — timed-out tasks get their fallback.
(fork-join {:budget-ms 15000}
[:tags #(query-tags candidate-tags) {}]
[:kg #(expand-via-kg vanilla-ids) #{}])
;; => {:tags {...} :kg #{...}}
Options:
:budget-ms — total time budget for all tasks (default 15000)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 |