Skip to content

Commit f75a04b

Browse files
authored
refactor(iroh): Remove with_cancel, use run_until_cancelled (#3000)
## Description We manually created a function that was already provided by the CancellationToken. Use the one from the library for consistency. ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [x] Tests if relevant. - [x] All breaking changes documented.
1 parent 0d06320 commit f75a04b

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

iroh/src/magicsock/relay_actor.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
use std::{
77
collections::{BTreeMap, BTreeSet},
8-
future::Future,
98
net::{IpAddr, SocketAddr},
109
sync::{atomic::Ordering, Arc},
1110
time::{Duration, Instant},
@@ -326,8 +325,8 @@ impl RelayActor {
326325
match task_result {
327326
Ok((url, ping_success)) => {
328327
if !ping_success {
329-
with_cancel(
330-
self.cancel_token.child_token(),
328+
let token = self.cancel_token.child_token();
329+
token.run_until_cancelled(
331330
self.close_or_reconnect_relay(&url, "rebind-ping-fail")
332331
).await;
333332
}
@@ -349,7 +348,8 @@ impl RelayActor {
349348
}
350349
_ = cleanup_timer.tick() => {
351350
trace!("tick: cleanup");
352-
with_cancel(self.cancel_token.child_token(), self.clean_stale_relay()).await;
351+
let cancel_token = self.cancel_token.child_token();
352+
cancel_token.run_until_cancelled(self.clean_stale_relay()).await;
353353
}
354354
}
355355
}
@@ -833,19 +833,6 @@ impl Iterator for PacketSplitIter {
833833
}
834834
}
835835

836-
async fn with_cancel<F>(token: CancellationToken, f: F)
837-
where
838-
F: Future<Output = ()>,
839-
{
840-
tokio::select! {
841-
_ = token.cancelled_owned() => {
842-
// abort
843-
}
844-
_ = f => {
845-
}
846-
}
847-
}
848-
849836
#[cfg(test)]
850837
mod tests {
851838
use super::*;

0 commit comments

Comments
 (0)