Expand description
Async Server Sent Event parser and encoder.
§Example
use async_sse::{decode, encode, Event};
use async_std::prelude::*;
use async_std::io::BufReader;
use async_std::task;
#[async_std::main]
async fn main() -> http_types::Result<()> {
// Create an encoder + sender pair and send a message.
let (sender, encoder) = encode();
task::spawn(async move {
sender.send("cat", "chashu", None).await;
});
// Decode messages using a decoder.
let mut reader = decode(BufReader::new(encoder));
let event = reader.next().await.unwrap()?;
// Match and handle the event
Ok(())
}
§References
Structs§
- An SSE protocol decoder.
- An SSE protocol encoder.
- An SSE event with a data payload.
- The sending side of the encoder.
Enums§
- The kind of SSE event sent.
Functions§
- Decode a new incoming SSE connection.
- Create a new SSE encoder.
- Upgrade an HTTP connection into an SSE session.