Skip to content

Commit d3be744

Browse files
authored
feat(wasm): Remove direct use of tokio::spawn in favor of matrix-sdk-common (#5159)
Mechanical move from tokio::spawn to matrix_sdk_common::executor::spawn that has support for Wasm platforms. On non-Wasm, this shim defaults to tokio::spawn.
1 parent ca63d60 commit d3be744

File tree

18 files changed

+57
-40
lines changed

18 files changed

+57
-40
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/matrix-sdk-crypto/src/machine/tests/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ use std::{collections::BTreeMap, iter, ops::Not, sync::Arc, time::Duration};
1717
use assert_matches2::{assert_let, assert_matches};
1818
use futures_util::{pin_mut, FutureExt, StreamExt};
1919
use itertools::Itertools;
20-
use matrix_sdk_common::deserialized_responses::{
21-
AlgorithmInfo, UnableToDecryptInfo, UnableToDecryptReason, UnsignedDecryptionResult,
22-
UnsignedEventLocation, VerificationLevel, VerificationState, WithheldCode,
20+
use matrix_sdk_common::{
21+
deserialized_responses::{
22+
AlgorithmInfo, UnableToDecryptInfo, UnableToDecryptReason, UnsignedDecryptionResult,
23+
UnsignedEventLocation, VerificationLevel, VerificationState, WithheldCode,
24+
},
25+
executor::spawn,
2326
};
2427
use matrix_sdk_test::{async_test, message_like_event_content, ruma_response_from_json, test_json};
2528
use ruma::{
@@ -1254,7 +1257,7 @@ async fn test_wait_on_key_query_doesnt_block_store() {
12541257
// Start a background task that will wait for the key query to finish silently
12551258
// in the background.
12561259
let machine_cloned = machine.clone();
1257-
let wait = tokio::spawn(async move {
1260+
let wait = spawn(async move {
12581261
let machine = machine_cloned;
12591262
let user_devices =
12601263
machine.get_user_devices(alice_id(), Some(Duration::from_secs(10))).await.unwrap();

crates/matrix-sdk-crypto/src/session_manager/sessions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ impl SessionManager {
590590
mod tests {
591591
use std::{collections::BTreeMap, iter, ops::Deref, sync::Arc, time::Duration};
592592

593-
use matrix_sdk_common::locks::RwLock as StdRwLock;
593+
use matrix_sdk_common::{executor::spawn, locks::RwLock as StdRwLock};
594594
use matrix_sdk_test::{async_test, ruma_response_from_json};
595595
use ruma::{
596596
api::client::keys::claim_keys::v3::Response as KeyClaimResponse, device_id,
@@ -747,9 +747,9 @@ mod tests {
747747
let bob_user_id = bob.user_id().to_owned();
748748

749749
#[allow(unknown_lints, clippy::redundant_async_block)] // false positive
750-
tokio::spawn(async move {
751-
manager.get_missing_sessions(iter::once(bob_user_id.deref())).await
752-
})
750+
spawn(
751+
async move { manager.get_missing_sessions(iter::once(bob_user_id.deref())).await },
752+
)
753753
};
754754

755755
// the initial `/keys/query` completes, and we start another

crates/matrix-sdk-ui/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ indexmap.workspace = true
4444
itertools.workspace = true
4545
matrix-sdk = { workspace = true, features = ["e2e-encryption"] }
4646
matrix-sdk-base.workspace = true
47+
matrix-sdk-common.workspace = true
4748
mime.workspace = true
4849
once_cell.workspace = true
4950
pin-project-lite.workspace = true

crates/matrix-sdk-ui/tests/integration/timeline/pinned_event.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use matrix_sdk::{
1212
Client, Room,
1313
};
1414
use matrix_sdk_base::deserialized_responses::TimelineEvent;
15+
use matrix_sdk_common::executor::spawn;
1516
use matrix_sdk_test::{
1617
async_test, event_factory::EventFactory, JoinedRoomBuilder, StateTestEvent,
1718
SyncResponseBuilder, BOB,
@@ -629,7 +630,7 @@ async fn test_ensure_max_concurrency_is_observed() {
629630
let room = client.get_room(&room_id).unwrap();
630631

631632
// Start loading the pinned event timeline asynchronously.
632-
let handle = tokio::spawn({
633+
let handle = spawn({
633634
let timeline_builder = room.timeline_builder().with_focus(pinned_events_focus(100));
634635
async {
635636
let _ = timeline_builder.build().await;

crates/matrix-sdk-ui/tests/integration/timeline/profiles.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::{sync::Arc, time::Duration};
1616

1717
use assert_matches::assert_matches;
1818
use matrix_sdk::{config::SyncSettings, test_utils::logged_in_client_with_server};
19+
use matrix_sdk_common::executor::spawn;
1920
use matrix_sdk_test::{
2021
async_test, event_factory::EventFactory, mocks::mock_encryption_state, JoinedRoomBuilder,
2122
SyncResponseBuilder, ALICE, BOB, CAROL, DEFAULT_TEST_ROOM_ID,
@@ -127,7 +128,7 @@ async fn test_update_sender_profiles() {
127128

128129
// Spawn fetch_members as a background task, so we can observe the missing
129130
// profiles being set to pending first.
130-
let hdl = tokio::spawn({
131+
let hdl = spawn({
131132
let timeline = timeline.clone();
132133
async move {
133134
timeline.fetch_members().await;

crates/matrix-sdk-ui/tests/integration/timeline/subscribe.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use assert_matches2::assert_let;
1919
use eyeball_im::VectorDiff;
2020
use futures_util::StreamExt;
2121
use matrix_sdk::{config::SyncSettings, test_utils::logged_in_client_with_server};
22+
use matrix_sdk_common::executor::spawn;
2223
use matrix_sdk_test::{
2324
async_test, event_factory::EventFactory, mocks::mock_encryption_state,
2425
GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder, ALICE, BOB,
@@ -57,7 +58,7 @@ async fn test_batched() {
5758
let timeline = room.timeline_builder().event_filter(|_, _| true).build().await.unwrap();
5859
let (_, mut timeline_stream) = timeline.subscribe().await;
5960

60-
let hdl = tokio::spawn(async move {
61+
let hdl = spawn(async move {
6162
let next_batch = timeline_stream.next().await.unwrap();
6263
// There can be more than three updates because we add things like
6364
// date dividers and implicit read receipts

crates/matrix-sdk/src/authentication/oauth/qrcode/login.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ mod test {
332332
use assert_matches2::{assert_let, assert_matches};
333333
use futures_util::{join, StreamExt};
334334
use matrix_sdk_base::crypto::types::{qr_login::QrCodeModeData, SecretsBundle};
335+
use matrix_sdk_common::executor::spawn;
335336
use matrix_sdk_test::async_test;
336337
use serde_json::json;
337338

@@ -469,7 +470,7 @@ mod test {
469470
let login_bob = oauth.login_with_qr_code(&qr_code, Some(&registration_data));
470471
let mut updates = login_bob.subscribe_to_progress();
471472

472-
let updates_task = tokio::spawn(async move {
473+
let updates_task = spawn(async move {
473474
let mut sender = Some(sender);
474475

475476
while let Some(update) = updates.next().await {
@@ -487,7 +488,7 @@ mod test {
487488
}
488489
});
489490
let alice_task =
490-
tokio::spawn(async { grant_login(alice, receiver, AliceBehaviour::HappyPath).await });
491+
spawn(async { grant_login(alice, receiver, AliceBehaviour::HappyPath).await });
491492

492493
join!(
493494
async {
@@ -557,7 +558,7 @@ mod test {
557558
let login_bob = oauth.login_with_qr_code(&qr_code, Some(&registration_data));
558559
let mut updates = login_bob.subscribe_to_progress();
559560

560-
let _updates_task = tokio::spawn(async move {
561+
let _updates_task = spawn(async move {
561562
let mut sender = Some(sender);
562563

563564
while let Some(update) = updates.next().await {
@@ -574,8 +575,7 @@ mod test {
574575
}
575576
}
576577
});
577-
let _alice_task =
578-
tokio::spawn(async move { grant_login(alice, receiver, alice_behavior).await });
578+
let _alice_task = spawn(async move { grant_login(alice, receiver, alice_behavior).await });
579579
login_bob.await
580580
}
581581

@@ -681,7 +681,7 @@ mod test {
681681
let login_bob = oauth.login_with_qr_code(&qr_code, Some(&registration_data));
682682
let mut updates = login_bob.subscribe_to_progress();
683683

684-
let _updates_task = tokio::spawn(async move {
684+
let _updates_task = spawn(async move {
685685
let mut sender = Some(sender);
686686

687687
while let Some(update) = updates.next().await {
@@ -699,9 +699,7 @@ mod test {
699699
}
700700
});
701701
let _alice_task =
702-
tokio::spawn(
703-
async move { grant_login(alice, receiver, AliceBehaviour::HappyPath).await },
704-
);
702+
spawn(async move { grant_login(alice, receiver, AliceBehaviour::HappyPath).await });
705703
let error = login_bob.await.unwrap_err();
706704

707705
assert_matches!(

crates/matrix-sdk/src/authentication/oauth/qrcode/secure_channel.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ pub(super) mod test {
234234
};
235235

236236
use matrix_sdk_base::crypto::types::qr_login::QrCodeMode;
237+
use matrix_sdk_common::executor::spawn;
237238
use matrix_sdk_test::async_test;
238239
use serde_json::json;
239240
use similar_asserts::assert_eq;
@@ -358,7 +359,7 @@ pub(super) mod test {
358359

359360
let qr_code_data = alice.qr_code_data().clone();
360361

361-
let bob_task = tokio::spawn(async move {
362+
let bob_task = spawn(async move {
362363
EstablishedSecureChannel::from_qr_code(
363364
reqwest::Client::new(),
364365
&qr_code_data,
@@ -368,7 +369,7 @@ pub(super) mod test {
368369
.expect("Bob should be able to fully establish the secure channel.")
369370
});
370371

371-
let alice_task = tokio::spawn(async move {
372+
let alice_task = spawn(async move {
372373
alice
373374
.connect()
374375
.await

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ mod tests {
261261
time::Duration,
262262
};
263263

264+
use matrix_sdk_common::executor::spawn;
264265
use matrix_sdk_test::{async_test, test_json};
265266
use wiremock::{
266267
matchers::{method, path},
@@ -302,7 +303,7 @@ mod tests {
302303
.mount(&server)
303304
.await;
304305

305-
let bg_task = tokio::spawn(async move {
306+
let bg_task = spawn(async move {
306307
futures_util::future::join_all((0..10).map(|_| client.whoami())).await
307308
});
308309

@@ -346,7 +347,7 @@ mod tests {
346347
.mount(&server)
347348
.await;
348349

349-
let bg_task = tokio::spawn(async move {
350+
let bg_task = spawn(async move {
350351
futures_util::future::join_all((0..254).map(|_| client.whoami())).await
351352
});
352353

0 commit comments

Comments
 (0)