Skip to main content

Module sse

Module sse 

Source
Expand description

Server-Sent Events response support.

SseResponse is an IntoResponse wrapper for any stream of SseEvent values. It sets the SSE-mandated headers (Content-Type: text/event-stream, Cache-Control: no-cache) and frames each event per the WHATWG SSE spec.

§Example

use futures::stream;
use typeway_server::{SseEvent, SseResponse};

async fn ticker() -> SseResponse<impl futures::Stream<Item = SseEvent>> {
    let s = stream::iter((0..3).map(|i| SseEvent::data(format!("tick {i}"))));
    SseResponse::new(s)
}

Structs§

SseEvent
A single Server-Sent Event.
SseResponse
An SSE response: any stream of SseEvent values, plus the right headers.

Functions§

keep_alive
Inject periodic comment frames (:keepalive\n\n) into an SSE stream.