io.pedestal.http.sse

COMMENT_FIELD

counted-thread-factory

(counted-thread-factory name-format daemon)

Create a ThreadFactory that maintains a counter for naming Threads. name-format specifies thread names - use %d to include counter daemon is a flag for whether threads are daemons or not

CRLF

daemon-thread-factory

DATA_FIELD

do-heartbeat

(do-heartbeat channel)(do-heartbeat channel {:keys [on-client-disconnect]})

end-event-stream

deprecated in 0.4.0

(end-event-stream {end-fn :io.pedestal.http.sse/end-event-stream})

DEPRECATED. Given a context, clean up the event stream it represents.

EVENT_FIELD

get-bytes

(get-bytes s)

ID_FIELD

mk-data

(mk-data name data)(mk-data name data id)

scheduler

send-event

(send-event channel name data)(send-event channel name data id)(send-event channel name data id put-fn)

sse-setup

(sse-setup & args)

See start-event-stream. This function is for backward compatibility.

start-event-stream

(start-event-stream stream-ready-fn)(start-event-stream stream-ready-fn heartbeat-delay)(start-event-stream stream-ready-fn heartbeat-delay bufferfn-or-n)(start-event-stream stream-ready-fn heartbeat-delay bufferfn-or-n opts)

Returns an interceptor which will start a Server Sent Event stream with the requesting client, and set the ServletResponse to go async. After the request handling context has been paused in the Servlet thread, stream-ready-fn will be called in a future, with the resulting context from setting up the SSE event stream.

opts is a map with optional keys:

:on-client-disconnect - A function of one argument which will be called when the client permanently disconnects.

start-stream

(start-stream stream-ready-fn context heartbeat-delay)(start-stream stream-ready-fn context heartbeat-delay bufferfn-or-n)(start-stream stream-ready-fn context heartbeat-delay bufferfn-or-n opts)

Starts an SSE event stream and initiates a heartbeat to keep the connection alive. stream-ready-fn will be called with a core.async channel. The application can then put maps with keys :name and :data on that channel to cause SSE events to be sent to the client. Either the client or the application may close the channel to terminate and clean up the event stream; the client closes it by closing the connection.

The SSE’s core.async buffer can either be a fixed buffer (n) or a 0-arity function that returns a buffer.

UTF-8