mirror of
https://github.com/tokio-rs/axum.git
synced 2024-12-29 15:49:16 +01:00
6d787665d6
Example usage: ```rust use axum::{prelude::*, sse::{sse, Event, KeepAlive}}; use tokio_stream::StreamExt as _; use futures::stream::{self, Stream}; use std::{ time::Duration, convert::Infallible, }; let app = route("/sse", sse(make_stream).keep_alive(KeepAlive::default())); async fn make_stream( // you can also put extractors here ) -> Result<impl Stream<Item = Result<Event, Infallible>>, Infallible> { // A `Stream` that repeats an event every second let stream = stream::repeat_with(|| Event::default().data("hi!")) .map(Ok) .throttle(Duration::from_secs(1)); Ok(stream) } ``` Implementation is based on [warp's](https://github.com/seanmonstar/warp/blob/master/src/filters/sse.rs) |
||
---|---|---|
.. | ||
extract | ||
handler | ||
service | ||
ws | ||
body.rs | ||
buffer.rs | ||
lib.rs | ||
macros.rs | ||
response.rs | ||
routing.rs | ||
sse.rs | ||
tests.rs | ||
util.rs |