Add time out to map discovery
This commit is contained in:
2 files changed
+14
-8
No files matched your search
@@ -189,11 +189,16 @@ impl Discoverer {
|
||||
F: Fn(UdpDiscovery, SocketAddr) -> Option<T>,
|
||||
{
|
||||
let mut reply = ReceiverStream::new(self.subscribe(0).await?);
|
||||
loop {
|
||||
let (reply, addr) = reply.next().await.ok_or(Error::ConnectionUnavaliable)??;
|
||||
if let Some(result) = map(reply, addr) {
|
||||
return Ok(result);
|
||||
}
|
||||
tokio::select! {
|
||||
v = async {
|
||||
loop {
|
||||
let (reply, addr) = reply.next().await.ok_or(Error::ConnectionUnavaliable)??;
|
||||
if let Some(result) = map(reply, addr) {
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
} => v,
|
||||
_ = tokio::time::sleep(*MAXIMUM_WAIT) => Err::<T, Error>(Error::DiscoveryTimeout),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -198,6 +198,7 @@ impl Sink<(BcUdp, SocketAddr)> for BcUdpSource {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
enum State {
|
||||
Normal, // Normal recieve
|
||||
Flushing, // Used to send ack packets and things in the buffer
|
||||
@@ -298,15 +299,15 @@ impl Stream for UdpPayloadSource {
|
||||
let mut this = self.get_mut();
|
||||
match this.state {
|
||||
State::Normal => {
|
||||
this.state = State::YieldNow;
|
||||
// this.state = State::YieldNow;
|
||||
// Handle resend events
|
||||
this.maintanence(cx);
|
||||
// Data ready to go
|
||||
if let Some(payload) = this.recieved.remove(&this.packets_want) {
|
||||
this.packets_want += 1;
|
||||
// error!("packets_want: {}", this.packets_want);
|
||||
return Poll::Ready(Some(Ok(payload)));
|
||||
}
|
||||
// Handle resend events
|
||||
this.maintanence(cx);
|
||||
// Normal behaviors
|
||||
match this.inner.poll_next_unpin(cx) {
|
||||
Poll::Ready(Some(Ok((
|
||||
|
||||
Reference in new issue
Block a user