Skip to content

Commit 2a71221

Browse files
committed
wg_webclient/wg_device: declare connected ref outside of the closure.
This ensures that the reference to the connected device is valid for the entire lifetime of the closure.
1 parent 2b58d68 commit 2a71221

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: wg-webclient/src/wg_device.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ fn create_onmessage_closure(
200200
message_pcap: Weak<RefCell<PcapNgWriter<Vec<u8>>>>,
201201
connect_cb: js_sys::Function,
202202
) -> Closure<dyn FnMut(MessageEvent) -> ()> {
203+
let connected = Rc::new(RefCell::new(false));
203204
Closure::<dyn FnMut(_)>::new(move |e: MessageEvent| {
204205
let data = e.data();
205206
let data = match data.dyn_into::<web_sys::Blob>() {
@@ -214,7 +215,7 @@ fn create_onmessage_closure(
214215
let message_tun = message_tun.clone();
215216
let message_vec = message_vec.clone();
216217
let message_pcap = message_pcap.clone();
217-
let connected = Rc::new(RefCell::new(false));
218+
let connected = connected.clone();
218219
let connect_cb = connect_cb.clone();
219220
spawn_local(async move {
220221
let array_buffer = wasm_bindgen_futures::JsFuture::from(data.array_buffer()).await.unwrap();

0 commit comments

Comments
 (0)