Skip to content

Commit c4a6514

Browse files
committed
do not destuct JoinHandle
1 parent e35ac74 commit c4a6514

File tree

1 file changed

+19
-10
lines changed
  • crates/matrix-sdk/src/widget

1 file changed

+19
-10
lines changed

crates/matrix-sdk/src/widget/mod.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use std::{fmt, time::Duration};
1818

1919
use async_channel::{Receiver, Sender};
20+
use matrix_sdk_common::executor;
2021
use ruma::api::client::delayed_events::DelayParameters;
2122
use serde::de::{self, Deserialize, Deserializer, Visitor};
2223
use tokio::sync::mpsc::{unbounded_channel, UnboundedSender};
@@ -67,6 +68,9 @@ pub struct WidgetDriver {
6768
///
6869
/// Only set if a subscription happened ([`Action::Subscribe`]).
6970
event_forwarding_guard: Option<DropGuard>,
71+
72+
/// JoinHandle for the matrix event subscribe task.
73+
matrix_subscribe_join_handle: Option<executor::JoinHandle<()>>,
7074
}
7175

7276
/// A handle that encapsulates the communication between a widget driver and the
@@ -115,7 +119,13 @@ impl WidgetDriver {
115119
let (from_widget_tx, from_widget_rx) = async_channel::unbounded();
116120
let (to_widget_tx, to_widget_rx) = async_channel::unbounded();
117121

118-
let driver = Self { settings, from_widget_rx, to_widget_tx, event_forwarding_guard: None };
122+
let driver = Self {
123+
settings,
124+
from_widget_rx,
125+
to_widget_tx,
126+
event_forwarding_guard: None,
127+
matrix_subscribe_join_handle: None,
128+
};
119129
let channels = WidgetDriverHandle { from_widget_tx, to_widget_rx };
120130

121131
(driver, channels)
@@ -139,17 +149,15 @@ impl WidgetDriver {
139149
let (incoming_msg_tx, mut incoming_msg_rx) = unbounded_channel();
140150

141151
// Forward all of the incoming messages from the widget.
142-
matrix_sdk_common::executor::spawn({
152+
let _handle = executor::spawn({
143153
let incoming_msg_tx = incoming_msg_tx.clone();
144154
let from_widget_rx = self.from_widget_rx.clone();
145155
async move {
146156
while let Ok(msg) = from_widget_rx.recv().await {
147157
let _ = incoming_msg_tx.send(IncomingMessage::WidgetMessage(msg));
148158
}
149159
}
150-
})
151-
.await
152-
.map_err(|_| ())?;
160+
});
153161

154162
// Create widget API machine.
155163
let (mut widget_machine, initial_actions) = WidgetMachine::new(
@@ -178,7 +186,6 @@ impl WidgetDriver {
178186
.await?;
179187
}
180188
}
181-
182189
Ok(())
183190
}
184191

@@ -256,12 +263,10 @@ impl WidgetDriver {
256263
(token.child_token(), token.drop_guard())
257264
};
258265

259-
self.event_forwarding_guard = Some(guard);
260-
261266
let mut matrix = matrix_driver.events();
262267
let incoming_msg_tx = incoming_msg_tx.clone();
263268

264-
matrix_sdk_common::executor::spawn(async move {
269+
let handle = executor::spawn(async move {
265270
loop {
266271
tokio::select! {
267272
_ = stop_forwarding.cancelled() => {
@@ -275,11 +280,15 @@ impl WidgetDriver {
275280
}
276281
}
277282
}
278-
}).await.map_err(|_|())?;
283+
});
284+
285+
self.matrix_subscribe_join_handle = Some(handle);
286+
self.event_forwarding_guard = Some(guard);
279287
}
280288

281289
Action::Unsubscribe => {
282290
self.event_forwarding_guard = None;
291+
self.matrix_subscribe_join_handle = None;
283292
}
284293
}
285294

0 commit comments

Comments
 (0)