Liking cljdoc? Tell your friends :D

hive.events.async

Async extensions for hive-events.

Provides advanced async patterns beyond basic dispatch:

  • Timeout-wrapped dispatch
  • Retry with backoff
  • Debounced dispatch
  • Event streams (pub/sub)
  • Saga/process manager patterns

JVM-first with core.async, graceful degradation on CLJS.

Async extensions for hive-events.

Provides advanced async patterns beyond basic dispatch:
- Timeout-wrapped dispatch
- Retry with backoff
- Debounced dispatch
- Event streams (pub/sub)
- Saga/process manager patterns

JVM-first with core.async, graceful degradation on CLJS.
raw docstring

dispatch-debouncedclj

(dispatch-debounced debounce-id event delay-ms)

Dispatch event after delay, canceling previous pending dispatch.

Useful for search-as-you-type, resize handlers, etc.

(dispatch-debounced :search [:search/query "foo"] 300)

Dispatch event after delay, canceling previous pending dispatch.

Useful for search-as-you-type, resize handlers, etc.

(dispatch-debounced :search [:search/query "foo"] 300)
sourceraw docstring

dispatch-throttledclj

(dispatch-throttled throttle-id event interval-ms)

Dispatch event at most once per interval.

(dispatch-throttled :scroll [:ui/scroll-position pos] 100)

Dispatch event at most once per interval.

(dispatch-throttled :scroll [:ui/scroll-position pos] 100)
sourceraw docstring

dispatch-with-retryclj

(dispatch-with-retry event)
(dispatch-with-retry event
                     {:keys [max-retries initial-delay-ms max-delay-ms
                             backoff-factor retry-pred]
                      :or {max-retries 3
                           initial-delay-ms 100
                           max-delay-ms 10000
                           backoff-factor 2
                           retry-pred (constantly false)}})

Dispatch event with exponential backoff retry.

Options:

  • :max-retries - Maximum retry attempts (default: 3)
  • :initial-delay-ms - First retry delay (default: 100)
  • :max-delay-ms - Maximum retry delay (default: 10000)
  • :backoff-factor - Multiplier per retry (default: 2)
  • :retry-pred - fn [context] -> boolean, whether to retry

Returns channel with final result or :max-retries-exceeded.

Dispatch event with exponential backoff retry.

Options:
- :max-retries - Maximum retry attempts (default: 3)
- :initial-delay-ms - First retry delay (default: 100)
- :max-delay-ms - Maximum retry delay (default: 10000)
- :backoff-factor - Multiplier per retry (default: 2)
- :retry-pred - fn [context] -> boolean, whether to retry

Returns channel with final result or :max-retries-exceeded.
sourceraw docstring

dispatch-with-timeoutclj

(dispatch-with-timeout event timeout-ms)

Dispatch event with timeout.

Returns a channel that receives:

  • {:status :ok :context ctx} on success
  • {:status :timeout} on timeout

(dispatch-with-timeout [:user/fetch 123] 5000)

Dispatch event with timeout.

Returns a channel that receives:
- {:status :ok :context ctx} on success
- {:status :timeout} on timeout

(dispatch-with-timeout [:user/fetch 123] 5000)
sourceraw docstring

publish-eventclj

(publish-event event)

Publish event to the event stream.

Events can be subscribed to by topic (first element).

Publish event to the event stream.

Events can be subscribed to by topic (first element).
sourceraw docstring

sagaclj

(saga topics handler)

Create a saga (long-running process) that reacts to events.

A saga is a go-block that:

  1. Subscribes to specified event topics
  2. Runs handler for each event
  3. Can dispatch new events based on state

Returns a channel that closes the saga when closed.

(saga [:order/created :payment/completed] (fn [event state] (case (first event) :order/created {:state (assoc state :order (second event)) :dispatch [:payment/initiate (:id (second event))]}

  :payment/completed
  {:state (assoc state :paid? true)
   :dispatch [:fulfillment/start (:order-id state)]})))
Create a saga (long-running process) that reacts to events.

A saga is a go-block that:
1. Subscribes to specified event topics
2. Runs handler for each event
3. Can dispatch new events based on state

Returns a channel that closes the saga when closed.

(saga [:order/created :payment/completed]
  (fn [event state]
    (case (first event)
      :order/created
      {:state (assoc state :order (second event))
       :dispatch [:payment/initiate (:id (second event))]}

      :payment/completed
      {:state (assoc state :paid? true)
       :dispatch [:fulfillment/start (:order-id state)]})))
sourceraw docstring

subscribe-eventsclj

(subscribe-events topic)

Subscribe to events by topic.

Returns a channel that receives events with the given topic.

(let [ch (subscribe-events :user/login)] (go-loop [] (when-let [event (<! ch)] (println "Login event:" event) (recur))))

Subscribe to events by topic.

Returns a channel that receives events with the given topic.

(let [ch (subscribe-events :user/login)]
  (go-loop []
    (when-let [event (<! ch)]
      (println "Login event:" event)
      (recur))))
sourceraw docstring

unsubscribe-eventsclj

(unsubscribe-events topic ch)

Unsubscribe channel from topic.

Unsubscribe channel from topic.
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