Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Clone for AbortHandle #6621

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tokio/src/runtime/task/abort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,11 @@ impl Drop for AbortHandle {
self.raw.drop_abort_handle();
}
}

impl Clone for AbortHandle {
/// Returns a cloned `AbortHandle` that can be used to remotely abort this task.
fn clone(&self) -> Self {
self.raw.ref_inc();
Self::new(self.raw)
}
}
23 changes: 23 additions & 0 deletions tokio/src/runtime/tests/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,29 @@ fn drop_abort_handle2() {
handle.assert_dropped();
}

#[test]
fn drop_abort_handle_clone() {
let (ad, handle) = AssertDrop::new();
let (notified, join) = unowned(
async {
drop(ad);
unreachable!()
},
NoopSchedule,
Id::next(),
);
let abort = join.abort_handle();
let abort_clone = abort.clone();
drop(join);
handle.assert_not_dropped();
drop(notified);
handle.assert_not_dropped();
drop(abort);
handle.assert_not_dropped();
drop(abort_clone);
handle.assert_dropped();
}

// Shutting down through Notified works
#[test]
fn create_shutdown1() {
Expand Down
Loading