task: implement Clone for AbortHandle (#6621)

This commit is contained in:
Aaron Schweiger
2024-06-07 09:17:25 +02:00
committed by GitHub
parent 8e15c234c6
commit 126ce89bb4
2 changed files with 31 additions and 0 deletions
+8
View File
@@ -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
View File
@@ -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() {