Liking cljdoc? Tell your friends :D

hive-weave.timed

Timed wrappers for interceptors and handlers.

Wraps any function with a timeout budget so it can't hang the caller. Primary use: event system interceptors that may call external services.

  • wrap-timed — wrap any (fn [x] -> x) with timeout
  • ->timed-interceptor — interceptor with timeout on :before/:after
  • timed-handler — handler with timeout + fallback
Timed wrappers for interceptors and handlers.

Wraps any function with a timeout budget so it can't hang the caller.
Primary use: event system interceptors that may call external services.

- `wrap-timed`            — wrap any (fn [x] -> x) with timeout
- `->timed-interceptor`   — interceptor with timeout on :before/:after
- `timed-handler`         — handler with timeout + fallback
raw docstring

->timed-interceptorclj

(->timed-interceptor & {:keys [id before after timeout-ms] :as m})

Create an interceptor with a timeout budget on :before and/or :after.

If either phase exceeds timeout-ms, it is cancelled and the context passes through unchanged (graceful degradation).

Usage: (->timed-interceptor :id :hk/smart-search-enrichment :timeout-ms 15000 :after (fn [ctx] ...expensive enrichment...))

On timeout: logs warning, context passes through, chain continues.

Create an interceptor with a timeout budget on :before and/or :after.

If either phase exceeds timeout-ms, it is cancelled and the context
passes through unchanged (graceful degradation).

Usage:
  (->timed-interceptor
    :id :hk/smart-search-enrichment
    :timeout-ms 15000
    :after (fn [ctx] ...expensive enrichment...))

On timeout: logs warning, context passes through, chain continues.
sourceraw docstring

timed-handlerclj

(timed-handler f {:keys [timeout-ms fallback name] :or {name "handler"}})

Wrap a handler function with a timeout + fallback. Unlike wrap-timed (which passes through input), this returns a specific fallback value on timeout.

(def safe-search (timed-handler search-fn {:timeout-ms 10000 :fallback {:error "timeout"}})) (safe-search params) ;; => result or {:error "timeout"}

Wrap a handler function with a timeout + fallback.
Unlike wrap-timed (which passes through input), this returns a
specific fallback value on timeout.

(def safe-search
  (timed-handler search-fn {:timeout-ms 10000 :fallback {:error "timeout"}}))
(safe-search params)  ;; => result or {:error "timeout"}
sourceraw docstring

wrap-timedclj

(wrap-timed f {:keys [timeout-ms name] :or {name "anonymous"}})

Wrap f with a timeout. Returns a new function that:

  • Runs f in a future
  • Returns f's result if it completes within timeout-ms
  • Returns passthrough (the original input) on timeout
  • Logs a warning on timeout

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

(def safe-enrich (wrap-timed enrich-fn {:timeout-ms 15000 :name "enrichment"}))

Wrap f with a timeout. Returns a new function that:
- Runs f in a future
- Returns f's result if it completes within timeout-ms
- Returns passthrough (the original input) on timeout
- Logs a warning on timeout

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

(def safe-enrich (wrap-timed enrich-fn {:timeout-ms 15000 :name "enrichment"}))
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