Side-effecting registries that live in parallel to the conversation atom: timers, pub/sub, and the pending-flow baton.
Three independent state shapes:
| atom | shape | role |
|---|---|---|
!pending-flows | {cid → flow-id} | one-shot baton between mount |
| and first SSE connect | ||
!timers | {cid → #{future}} | scheduled future-fired events |
!subscriptions | {topic → {[cid iid] event}} | live pub/sub routing |
Delivery — both timer fires and publish! — calls back into a
conversation via a dispatch function the server installs at startup
with install-dispatch!. Keeping the dependency one-way (server
requires async, async never requires server) avoids the circular
require that would otherwise emerge from
schedule-event! → dispatch! → kernel hook → schedule-event!.
Side-effecting registries that live in parallel to the conversation
atom: timers, pub/sub, and the pending-flow baton.
Three independent state shapes:
| atom | shape | role |
|-----------------|--------------------------------|--------------------------------|
| `!pending-flows`| `{cid → flow-id}` | one-shot baton between mount |
| | | and first SSE connect |
| `!timers` | `{cid → #{future}}` | scheduled future-fired events |
| `!subscriptions`| `{topic → {[cid iid] event}}` | live pub/sub routing |
Delivery — both timer fires and `publish!` — calls back into a
conversation via a dispatch function the server installs at startup
with [[install-dispatch!]]. Keeping the dependency one-way (server
requires async, async never requires server) avoids the circular
require that would otherwise emerge from
`schedule-event! → dispatch! → kernel hook → schedule-event!`.(cancel-timers! cid)Cancel every scheduled future for cid and forget them.
Cancel every scheduled future for `cid` and forget them.
(forget-pending-flow! cid)Drop any pending entry for cid (used when a conversation ends
before SSE ever attached).
Drop any pending entry for `cid` (used when a conversation ends before SSE ever attached).
(install-dispatch! f)Called once by the server at namespace load (or by tests that need delivery without booting http) so timer and pub/sub deliveries can route events back into live conversations.
Called once by the server at namespace load (or by tests that need delivery without booting http) so timer and pub/sub deliveries can route events back into live conversations.
(pending-flow cid)Pop and return the pending flow id for cid, if any. After this
call the cid no longer has a pending flow.
Pop and return the pending flow id for `cid`, if any. After this call the cid no longer has a pending flow.
(publish! topic msg)Asynchronously deliver msg to every live subscriber of topic.
Returns the number of subscribers targeted.
Asynchronously deliver `msg` to every live subscriber of `topic`. Returns the number of subscribers targeted.
(put-pending-flow! cid flow-id)Record the root flow id a freshly-minted cid should boot when its first SSE connect arrives.
Record the root flow id a freshly-minted cid should boot when its first SSE connect arrives.
(remove-subscriptions-for-cid! cid)Drop every subscription owned by cid (used on conversation end).
Drop every subscription owned by `cid` (used on conversation end).
(reset-state!)Wipe every async registry. Intended for tests / REPL iteration.
Wipe every async registry. Intended for tests / REPL iteration.
(schedule-event! {:keys [cid instance-id delay-ms event]})Schedule a future event for a cid/iid. The future is cancelled when the conversation ends; if the instance disappears first, delivery is a no-op.
Schedule a future event for a cid/iid. The future is cancelled when the conversation ends; if the instance disappears first, delivery is a no-op.
(subscribe! {:keys [cid instance-id topic event]})Subscribe cid/iid to topic; published values arrive as event.
Subscribe cid/iid to `topic`; published values arrive as `event`.
(subscriptions)Snapshot of topic subscriptions, for tests/inspection.
Snapshot of topic subscriptions, for tests/inspection.
(unsubscribe! {:keys [cid instance-id topic]})Remove one cid/iid subscription. If topic is nil, remove all of the
instance's subscriptions.
Remove one cid/iid subscription. If `topic` is nil, remove all of the instance's subscriptions.
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 |