implement Stream for Discovery (#5370)

This commit is contained in:
int88
2023-11-10 00:39:02 +08:00
committed by GitHub
parent c47a2393e3
commit 46cad7042c

View File

@ -14,11 +14,12 @@ use secp256k1::SecretKey;
use std::{
collections::{hash_map::Entry, HashMap, VecDeque},
net::{IpAddr, SocketAddr},
pin::Pin,
sync::Arc,
task::{Context, Poll},
task::{ready, Context, Poll},
};
use tokio::{sync::mpsc, task::JoinHandle};
use tokio_stream::wrappers::ReceiverStream;
use tokio_stream::{wrappers::ReceiverStream, Stream};
/// An abstraction over the configured discovery protocol.
///
@ -216,6 +217,14 @@ impl Discovery {
}
}
impl Stream for Discovery {
type Item = DiscoveryEvent;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Poll::Ready(Some(ready!(self.get_mut().poll(cx))))
}
}
#[cfg(test)]
impl Discovery {
/// Returns a Discovery instance that does nothing and is intended for testing purposes.