Skip to content

Commit 6c4a438

Browse files
authored
WidgetDriver: Use matrix_sdk_common::executor::spawn instead of tokio::spawn to make it wasm compatible. (#4959)
This PR is a revived version of: #4707 since it is now possible to easily add wasm support thanks to: #4572 Using the `executer::spawn` will select `tokio::spawn` or `wasm_bindgen_futures::spawn_local` based on what platform we are on. ~~They behave differently in that `tokio` actually starts the async block inside the spawn but the wasm `spawn` wrapper will only start the part that is not inside the `async` block and the join handle needs to be awaited for it to work.~~ This has now changed with: #4572. Now they behave the same and this PR becomes a very simple change.
1 parent 7272a34 commit 6c4a438

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

crates/matrix-sdk/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ oauth2 = { version = "5.0.0", default-features = false, features = ["reqwest", "
8686
once_cell = { workspace = true }
8787
percent-encoding = "2.3.1"
8888
pin-project-lite = { workspace = true }
89-
rand = { workspace = true , optional = true }
89+
rand = { workspace = true, optional = true }
9090
ruma = { workspace = true, features = [
9191
"rand",
9292
"unstable-msc2448",
@@ -105,6 +105,7 @@ sha2 = { workspace = true }
105105
tempfile = { workspace = true }
106106
thiserror = { workspace = true }
107107
tokio-stream = { workspace = true, features = ["sync"] }
108+
tokio-util = "0.7.13"
108109
tower = { version = "0.5.2", features = ["util"], optional = true }
109110
tracing = { workspace = true, features = ["attributes"] }
110111
uniffi = { workspace = true, optional = true }
@@ -125,7 +126,6 @@ backon = "1.5.0"
125126
# support *sending* streams, which makes it useless for us.
126127
reqwest = { workspace = true, features = ["stream", "gzip", "http2"] }
127128
tokio = { workspace = true, features = ["fs", "rt", "macros"] }
128-
tokio-util = "0.7.13"
129129
wiremock = { workspace = true, optional = true }
130130

131131
[dev-dependencies]

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

Lines changed: 3 additions & 2 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::spawn;
2021
use ruma::api::client::delayed_events::DelayParameters;
2122
use serde::de::{self, Deserialize, Deserializer, Visitor};
2223
use tokio::sync::mpsc::{unbounded_channel, UnboundedSender};
@@ -139,7 +140,7 @@ impl WidgetDriver {
139140
let (incoming_msg_tx, mut incoming_msg_rx) = unbounded_channel();
140141

141142
// Forward all of the incoming messages from the widget.
142-
tokio::spawn({
143+
spawn({
143144
let incoming_msg_tx = incoming_msg_tx.clone();
144145
let from_widget_rx = self.from_widget_rx.clone();
145146
async move {
@@ -259,7 +260,7 @@ impl WidgetDriver {
259260
let mut matrix = matrix_driver.events();
260261
let incoming_msg_tx = incoming_msg_tx.clone();
261262

262-
tokio::spawn(async move {
263+
spawn(async move {
263264
loop {
264265
tokio::select! {
265266
_ = stop_forwarding.cancelled() => {

0 commit comments

Comments
 (0)