implement Drop for client struct
All checks were successful
Build library & run tests / build (unix) (push) Successful in 34s
Build library & run tests / build (tcp) (push) Successful in 35s
Build library & run tests / docs (push) Successful in 37s

This commit is contained in:
Kodi Craft 2024-06-24 23:40:47 +02:00
parent b5870e62fe
commit bffb41e8a1
Signed by: kodi
GPG Key ID: 69D9EED60B242822

View File

@ -618,7 +618,7 @@ fn derive_protocol(input: proc_macro2::TokenStream) -> proc_macro2::TokenStream
// Create a struct which the client will use to communicate // Create a struct which the client will use to communicate
let client_recv_queue_wrapper = format_ident!("__{}RecvQueueWrapper", name); let client_recv_queue_wrapper = format_ident!("__{}RecvQueueWrapper", name);
let client_struct = quote! { let client_struct = quote! {
#[derive(Clone)] #[derive(::std::clone::Clone)]
struct #client_recv_queue_wrapper { struct #client_recv_queue_wrapper {
recv_queue: ::std::sync::Arc<::tokio::sync::Mutex<::tokio::sync::mpsc::Receiver<(u64, #answer_enum_name)>>>, recv_queue: ::std::sync::Arc<::tokio::sync::Mutex<::tokio::sync::mpsc::Receiver<(u64, #answer_enum_name)>>>,
} }
@ -665,8 +665,8 @@ fn derive_protocol(input: proc_macro2::TokenStream) -> proc_macro2::TokenStream
let connection_task = ::tokio::spawn(connection.run()); let connection_task = ::tokio::spawn(connection.run());
Ok(Self::new(send_queue, recv_queue, ::std::option::Option::Some(::std::sync::Arc::new(connection_task)), ready_notify)) Ok(Self::new(send_queue, recv_queue, ::std::option::Option::Some(::std::sync::Arc::new(connection_task)), ready_notify))
} }
pub fn close(self) { pub fn close(&mut self) {
if let ::std::option::Option::Some(task) = self.connection_task { if let ::std::option::Option::Some(task) = self.connection_task.take() {
task.abort(); task.abort();
} }
} }
@ -707,6 +707,11 @@ fn derive_protocol(input: proc_macro2::TokenStream) -> proc_macro2::TokenStream
} }
#(#client_impl)* #(#client_impl)*
} }
impl ::std::ops::Drop for #client_struct_name {
fn drop(&mut self) {
self.close();
}
}
}; };
let expanded = quote! { let expanded = quote! {