API reference

fast-twitch.server.sse

Complete generated reference for fast-twitch.server.sse

Using this namespace

(ns application.events
  (:require [fast-twitch.server.sse :as sse]))

(defn events-handler [_]
  (let [remaining (atom [{:data "one"} {:event "notice" :data "two"}])]
    (sse/response
      (fn []
        (let [event (first @remaining)]
          (swap! remaining next)
          event)))))

response accepts [next-event] or [next-event options] and returns a Ring response map. The zero-argument producer can return a Promise. Returning nil ends the stream. Allocate producer cursors inside the handler so concurrent responses cannot consume each other's events.

Option Behavior
:headers Optional map/nil; merged over SSE UTF-8 and no-cache defaults
:on-cancel Optional function/nil; receives cancellation/producer-failure reason and releases resources

An event requires string :data; optional fields are :event, :id and :retry. See exact event restrictions. Producer normal completion needs its own cleanup; :on-cancel is not called on ordinary EOF. Pulls await one event at a time with a zero high-water mark.

Runnable producer and both consumers · Generic SSE versus Datastar.

Upstream function reference

Pull-based SSE responses for ordinary Ring handlers.

response

(response next-event)
(response next-event options)

Function. Source


Source revision a4eb73f96836d034c7a24fe09dc7d51e4c581f64

Built with Fast-Twitch · Integrant · Datastar

Search documentation

Search pages and API symbols

Start hereWelcome to Fast-TwitchRing HTTP applications and configured native clients and transports in ClojureScript.Start hereGetting startedCompile and run your first Fast-Twitch server.Core conceptsRequest & responseUnderstand the maps at the center of a Fast-Twitch application.Core conceptsRoutingMatch URL patterns and compose handlers.Core conceptsMiddlewareWrap handlers with focused request and response behavior.GuidesHTML & IntegrantCompose a UI system with Integrant and render Hiccup.