Skip to main content

apalis_board_api/sse/
client.rs

1use std::{
2    pin::Pin,
3    task::{Context, Poll},
4};
5
6use apalis_board_types::LogEntry;
7use futures::{
8    Stream, StreamExt,
9    channel::mpsc::{Receiver, TryRecvError},
10};
11
12/// A client that receives log entries from a server-sent events (SSE) stream.
13#[derive(Debug)]
14pub struct Client(pub(crate) Receiver<LogEntry>);
15
16impl Stream for Client {
17    type Item = Result<LogEntry, TryRecvError>;
18
19    fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
20        self.0.poll_next_unpin(cx).map(|c| Ok(c).transpose())
21    }
22}