Crate async_sse

Source
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§

Decoder
An SSE protocol decoder.
Encoder
An SSE protocol encoder.
Message
An SSE event with a data payload.
Sender
The sending side of the encoder.

Enums§

Event
The kind of SSE event sent.

Functions§

decode
Decode a new incoming SSE connection.
encode
Create a new SSE encoder.
upgrade
Upgrade an HTTP connection into an SSE session.