immediately close ping task instead of waiting for the interval

This commit is contained in:
Toshit Chawda 2024-09-26 18:22:28 -07:00
parent 4239ecb713
commit 888044f63d
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D

View file

@ -258,10 +258,14 @@ pub async fn handle_wisp(stream: WispResult, id: String) -> anyhow::Result<()> {
}))); })));
let ping_mux = mux.clone(); let ping_mux = mux.clone();
let ping_event = event.clone();
set.spawn(async move { set.spawn(async move {
let mut interval = interval(Duration::from_secs(30)); let mut interval = interval(Duration::from_secs(30));
while ping_mux.send_ping(Payload::Bytes(BytesMut::new())).await.is_ok() { while ping_mux.send_ping(Payload::Bytes(BytesMut::new())).await.is_ok() {
interval.tick().await; select! {
_ = interval.tick() => (),
_ = ping_event.listen() => break,
};
} }
}); });
@ -281,6 +285,8 @@ pub async fn handle_wisp(stream: WispResult, id: String) -> anyhow::Result<()> {
let _ = mux.close().await; let _ = mux.close().await;
event.notify(usize::MAX); event.notify(usize::MAX);
trace!("waiting for tasks to close for wisp client id {:?}", id);
while set.join_next().await.is_some() {} while set.join_next().await.is_some() {}
debug!("wisp client id {:?} disconnected", id); debug!("wisp client id {:?} disconnected", id);