From ea5b757a483c4af524395cf24c468e85520b6e98 Mon Sep 17 00:00:00 2001 From: Dario Lencina Date: Fri, 26 Jul 2024 16:37:27 -0400 Subject: [PATCH] forget callbacks --- src/webtransport.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/webtransport.rs b/src/webtransport.rs index 9929534..86a7e8f 100644 --- a/src/webtransport.rs +++ b/src/webtransport.rs @@ -93,8 +93,6 @@ pub struct WebTransportTask { notification: Callback, #[allow(dead_code)] listeners: [Promise; 2], - #[allow(dead_code)] - callbacks: [Closure; 2], } impl WebTransportTask { @@ -102,13 +100,11 @@ impl WebTransportTask { transport: Rc, notification: Callback, listeners: [Promise; 2], - callbacks: [Closure; 2], ) -> WebTransportTask { WebTransportTask { transport, notification, listeners, - callbacks, } } } @@ -133,7 +129,7 @@ impl WebTransportService { on_bidirectional_stream: Callback, notification: Callback, ) -> Result { - let ConnectCommon(transport, listeners, callbacks) = + let ConnectCommon(transport, listeners) = Self::connect_common(url, ¬ification)?; let transport = Rc::new(transport); @@ -158,7 +154,6 @@ impl WebTransportService { transport, notification, listeners, - callbacks, )) } @@ -306,15 +301,17 @@ impl WebTransportService { .closed() .then(&closed_closure) .catch(&closed_closure); - + // forget closures + opened_closure.forget(); + closed_closure.forget(); + { let listeners = [ready, closed]; - let callbacks = [opened_closure, closed_closure]; - Ok(ConnectCommon(transport, listeners, callbacks)) + Ok(ConnectCommon(transport, listeners)) } } } -struct ConnectCommon(WebTransport, [Promise; 2], [Closure; 2]); +struct ConnectCommon(WebTransport, [Promise; 2]); pub fn process_binary(bytes: &Uint8Array, callback: &Callback>) { let data = bytes.to_vec();