Skip to content
Discussion options

You must be logged in to vote
async fn sse_handler_as_string(
    State(app_state): State<Arc<AppState>>,
) -> Sse<impl Stream<Item = Result<Event, BroadcastStreamRecvError>>> {
    use tokio_stream::StreamExt;

    let rx = app_state.tx_as_string.subscribe();

    let mystream = BroadcastStream::new(rx);
    let mystream = mystream.map(|s| Ok(Event::default().data(&s.unwrap())));

    Sse::new(mystream).keep_alive(KeepAlive::default())
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@frederikhors
Comment options

Answer selected by frederikhors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants