A
We released a new website w/ new guides! https://tokio.rs/ I would love feedback. Feel free to open issues on the repo: https://github.com/tokio-rs/website
Size: a a a
A
t
A
YM
K
V
tokio::spawn(async move {
let mut delay =
tokio::time::delay_for(Duration::from_secs(timeout));
loop {
select! {
_ = &mut delay => {
timeout_tx.send(());
break;
}
next = ch_rx.next() => {
// When sender handles are dropped, next will return Ok(None)
// So we check if next has actual value, to reset delay
// Otherwise that means that sender was dropped (because parent struct was dropped) and so we end this task
if next.is_some() {
delay = tokio::time::delay_for(Duration::from_millis(timeout));
} else {
break;
}
}
}
}
});
в самом хэндлере:loop {
// run concurrently timeout receiver and decoder, getting messages and handling them
select! {
_ = &mut timeout_rx => {
return Err(anyhow::anyhow!("Client disconnected because of timeout!"));
}
res = self.socket.next() => {
if let Some(parsed) = res {
self.handle(parsed?).await?;
} else {
return Err(anyhow::anyhow!("Client disconnected!"));
}
}
}
}V
V
V
D
D
D
D
if next.is_some() {
delay = tokio::time::delay_for(Duration::from_millis(timeout));delay отодвигаешьD
D
V
D
V
V