Using sse I need to transform BroadcastStream<String>
to BroadcastStream<sse::Event>
. Is it possible?
#2260
Answered
by
zoer
frederikhors
asked this question in
Q&A
Replies: 1 comment 1 reply
-
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())
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
frederikhors
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Using the code below I don't understand how to transform:
to
REPL: https://www.rustexplorer.com/b/8kla6t
Can you help me understand?
As you can see the issue is in the func
sse_handler_as_string()
.Beta Was this translation helpful? Give feedback.
All reactions