Skip to content
Discussion options

You must be logged in to vote

Using async_stream you simply return:

use axum::{
    extract::State,
    response::{sse::Event, Sse},
    routing::get,
    Router,
};
use futures::Stream;
use tokio::sync::oneshot;
use std::{
    convert::Infallible,
    net::SocketAddr,
    sync::{Arc, Mutex},
    time::Duration,
};

#[derive(Clone, Default)]
struct AppState {
    stream_handles: Arc<Mutex<Vec<oneshot::Sender<()>>>>,
}

#[tokio::main]
async fn main() {
    let state = AppState::default();

    let app = Router::new()
        .route("/stream", get(stream))
        .route("/end-all-streams", get(end_all_streams))
        .with_state(state);

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    println!("listening…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by sukhmel
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