xmtp_api_grpc/streams/
fake_empty.rs

1//! Create a fake stream that will always be pending
2//! this is a workaround for https://github.com/xmtp/xmtpd/issues/1440
3
4use prost::bytes::Bytes;
5use std::{
6    error::Error,
7    marker::PhantomData,
8    pin::Pin,
9    task::{Context, Poll},
10};
11
12use futures::{Stream, stream::FusedStream};
13
14/// This stream will always return Pending
15/// it should be used when subscribing with an empty topics list
16#[derive(Default, Clone)]
17pub struct FakeEmptyStream<E> {
18    _error: PhantomData<E>,
19}
20
21impl<E: Error> FakeEmptyStream<E> {
22    pub fn new() -> Self {
23        Self {
24            _error: PhantomData,
25        }
26    }
27}
28
29impl<E: Error> Stream for FakeEmptyStream<E> {
30    type Item = Result<hyper::body::Frame<Bytes>, E>;
31
32    fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
33        Poll::Pending
34    }
35}
36
37impl<T> Unpin for FakeEmptyStream<T> {}
38
39impl<E: Error> FusedStream for FakeEmptyStream<E> {
40    fn is_terminated(&self) -> bool {
41        true
42    }
43}