Liking cljdoc? Tell your friends :D

hive-weave.safe

Safe execution primitives — the antidote to bare @ and raw future.

Every bare @(future ...) or @(promise) is a potential hang. This namespace provides bounded alternatives that always terminate:

  • deref-safe — deref with timeout + fallback (never hangs)
  • deref-safe! — deref with timeout, throws on timeout (never hangs)
  • safe-future — future with timeout + Result return
  • safe-future! — future with timeout, throws on timeout

All primitives return within their timeout budget. No exceptions.

Safe execution primitives — the antidote to bare @ and raw future.

Every bare `@(future ...)` or `@(promise)` is a potential hang.
This namespace provides bounded alternatives that always terminate:

- `deref-safe`  — deref with timeout + fallback (never hangs)
- `deref-safe!` — deref with timeout, throws on timeout (never hangs)
- `safe-future`  — future with timeout + Result return
- `safe-future!` — future with timeout, throws on timeout

All primitives return within their timeout budget. No exceptions.
raw docstring

deref-safeclj

(deref-safe ref timeout-ms fallback)

Deref with timeout and fallback. Never hangs.

(deref-safe my-promise 5000 []) ;; => value or [] after 5s (deref-safe my-future 10000 nil) ;; => value or nil after 10s

Deref with timeout and fallback. Never hangs.

(deref-safe my-promise 5000 [])       ;; => value or [] after 5s
(deref-safe my-future 10000 nil)      ;; => value or nil after 10s
sourceraw docstring

deref-safe!clj

(deref-safe! ref timeout-ms)

Deref with timeout. Throws on timeout. Never hangs indefinitely.

(deref-safe! my-promise 5000) ;; => value or throws after 5s

Deref with timeout. Throws on timeout. Never hangs indefinitely.

(deref-safe! my-promise 5000)    ;; => value or throws after 5s
sourceraw docstring

safe-futurecljmacro

(safe-future opts & body)

Execute body in a future with timeout. Returns Result.

(safe-future {:timeout-ms 5000} (expensive-computation)) ;; => (ok result) or (err :weave/timeout {...})

Execute body in a future with timeout. Returns Result.

(safe-future {:timeout-ms 5000}
  (expensive-computation))
;; => (ok result) or (err :weave/timeout {...})
sourceraw docstring

safe-future-callclj

(safe-future-call {:keys [timeout-ms name] :or {name "anonymous"}} f)

Execute f in a future with timeout. Returns Result.

(safe-future-call {:timeout-ms 5000} #(expensive-computation)) ;; => (ok result) or (err :weave/timeout {...}) or (err :weave/exception {...})

Options: :timeout-ms — max execution time (required) :name — diagnostic label (optional)

Execute f in a future with timeout. Returns Result.

(safe-future-call {:timeout-ms 5000} #(expensive-computation))
;; => (ok result) or (err :weave/timeout {...}) or (err :weave/exception {...})

Options:
  :timeout-ms — max execution time (required)
  :name       — diagnostic label (optional)
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close