1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
/// An SSE message sender.
#[derive(Debug)]
pub struct Sender {
    sender: async_sse::Sender,
}

impl Sender {
    /// Create a new instance of `Sender`.
    pub(crate) fn new(sender: async_sse::Sender) -> Self {
        Self { sender }
    }

    /// Send data from the SSE channel.
    ///
    /// Each message constists of a "name" and "data".
    pub async fn send(&self, name: &str, data: impl AsRef<str>, id: Option<&str>) {
        self.sender.send(name, data.as_ref().as_bytes(), id).await;
    }
}