Async extensions for hive-events.
Provides advanced async patterns beyond basic dispatch:
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.
(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)
(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)
(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:
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.
(dispatch-with-timeout event timeout-ms)Dispatch event with timeout.
Returns a channel that receives:
(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)(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).
(saga topics handler)Create a saga (long-running process) that reacts to events.
A saga is a go-block that:
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)]})))(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))))(unsubscribe-events topic ch)Unsubscribe channel from topic.
Unsubscribe channel from topic.
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 |