mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-21 00:00:10 +02:00
task: implement Clone for AbortHandle (#6621)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user