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.
This commit is contained in:
Generated
+2
@@ -3185,6 +3185,7 @@ dependencies = [
|
||||
"json-structural-diff",
|
||||
"matrix-sdk",
|
||||
"matrix-sdk-base",
|
||||
"matrix-sdk-common",
|
||||
"matrix-sdk-test",
|
||||
"matrix-sdk-ui",
|
||||
"once_cell",
|
||||
@@ -3318,6 +3319,7 @@ dependencies = [
|
||||
"itertools 0.14.0",
|
||||
"matrix-sdk",
|
||||
"matrix-sdk-base",
|
||||
"matrix-sdk-common",
|
||||
"matrix-sdk-test",
|
||||
"mime",
|
||||
"once_cell",
|
||||
|
||||
@@ -17,9 +17,12 @@ use std::{collections::BTreeMap, iter, ops::Not, sync::Arc, time::Duration};
|
||||
use assert_matches2::{assert_let, assert_matches};
|
||||
use futures_util::{pin_mut, FutureExt, StreamExt};
|
||||
use itertools::Itertools;
|
||||
use matrix_sdk_common::deserialized_responses::{
|
||||
AlgorithmInfo, UnableToDecryptInfo, UnableToDecryptReason, UnsignedDecryptionResult,
|
||||
UnsignedEventLocation, VerificationLevel, VerificationState, WithheldCode,
|
||||
use matrix_sdk_common::{
|
||||
deserialized_responses::{
|
||||
AlgorithmInfo, UnableToDecryptInfo, UnableToDecryptReason, UnsignedDecryptionResult,
|
||||
UnsignedEventLocation, VerificationLevel, VerificationState, WithheldCode,
|
||||
},
|
||||
executor::spawn,
|
||||
};
|
||||
use matrix_sdk_test::{async_test, message_like_event_content, ruma_response_from_json, test_json};
|
||||
use ruma::{
|
||||
@@ -1254,7 +1257,7 @@ async fn test_wait_on_key_query_doesnt_block_store() {
|
||||
// Start a background task that will wait for the key query to finish silently
|
||||
// in the background.
|
||||
let machine_cloned = machine.clone();
|
||||
let wait = tokio::spawn(async move {
|
||||
let wait = spawn(async move {
|
||||
let machine = machine_cloned;
|
||||
let user_devices =
|
||||
machine.get_user_devices(alice_id(), Some(Duration::from_secs(10))).await.unwrap();
|
||||
|
||||
@@ -590,7 +590,7 @@ impl SessionManager {
|
||||
mod tests {
|
||||
use std::{collections::BTreeMap, iter, ops::Deref, sync::Arc, time::Duration};
|
||||
|
||||
use matrix_sdk_common::locks::RwLock as StdRwLock;
|
||||
use matrix_sdk_common::{executor::spawn, locks::RwLock as StdRwLock};
|
||||
use matrix_sdk_test::{async_test, ruma_response_from_json};
|
||||
use ruma::{
|
||||
api::client::keys::claim_keys::v3::Response as KeyClaimResponse, device_id,
|
||||
@@ -747,9 +747,9 @@ mod tests {
|
||||
let bob_user_id = bob.user_id().to_owned();
|
||||
|
||||
#[allow(unknown_lints, clippy::redundant_async_block)] // false positive
|
||||
tokio::spawn(async move {
|
||||
manager.get_missing_sessions(iter::once(bob_user_id.deref())).await
|
||||
})
|
||||
spawn(
|
||||
async move { manager.get_missing_sessions(iter::once(bob_user_id.deref())).await },
|
||||
)
|
||||
};
|
||||
|
||||
// the initial `/keys/query` completes, and we start another
|
||||
|
||||
@@ -44,6 +44,7 @@ indexmap.workspace = true
|
||||
itertools.workspace = true
|
||||
matrix-sdk = { workspace = true, features = ["e2e-encryption"] }
|
||||
matrix-sdk-base.workspace = true
|
||||
matrix-sdk-common.workspace = true
|
||||
mime.workspace = true
|
||||
once_cell.workspace = true
|
||||
pin-project-lite.workspace = true
|
||||
|
||||
@@ -12,6 +12,7 @@ use matrix_sdk::{
|
||||
Client, Room,
|
||||
};
|
||||
use matrix_sdk_base::deserialized_responses::TimelineEvent;
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use matrix_sdk_test::{
|
||||
async_test, event_factory::EventFactory, JoinedRoomBuilder, StateTestEvent,
|
||||
SyncResponseBuilder, BOB,
|
||||
@@ -629,7 +630,7 @@ async fn test_ensure_max_concurrency_is_observed() {
|
||||
let room = client.get_room(&room_id).unwrap();
|
||||
|
||||
// Start loading the pinned event timeline asynchronously.
|
||||
let handle = tokio::spawn({
|
||||
let handle = spawn({
|
||||
let timeline_builder = room.timeline_builder().with_focus(pinned_events_focus(100));
|
||||
async {
|
||||
let _ = timeline_builder.build().await;
|
||||
|
||||
@@ -16,6 +16,7 @@ use std::{sync::Arc, time::Duration};
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use matrix_sdk::{config::SyncSettings, test_utils::logged_in_client_with_server};
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use matrix_sdk_test::{
|
||||
async_test, event_factory::EventFactory, mocks::mock_encryption_state, JoinedRoomBuilder,
|
||||
SyncResponseBuilder, ALICE, BOB, CAROL, DEFAULT_TEST_ROOM_ID,
|
||||
@@ -127,7 +128,7 @@ async fn test_update_sender_profiles() {
|
||||
|
||||
// Spawn fetch_members as a background task, so we can observe the missing
|
||||
// profiles being set to pending first.
|
||||
let hdl = tokio::spawn({
|
||||
let hdl = spawn({
|
||||
let timeline = timeline.clone();
|
||||
async move {
|
||||
timeline.fetch_members().await;
|
||||
|
||||
@@ -19,6 +19,7 @@ use assert_matches2::assert_let;
|
||||
use eyeball_im::VectorDiff;
|
||||
use futures_util::StreamExt;
|
||||
use matrix_sdk::{config::SyncSettings, test_utils::logged_in_client_with_server};
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use matrix_sdk_test::{
|
||||
async_test, event_factory::EventFactory, mocks::mock_encryption_state,
|
||||
GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder, ALICE, BOB,
|
||||
@@ -57,7 +58,7 @@ async fn test_batched() {
|
||||
let timeline = room.timeline_builder().event_filter(|_, _| true).build().await.unwrap();
|
||||
let (_, mut timeline_stream) = timeline.subscribe().await;
|
||||
|
||||
let hdl = tokio::spawn(async move {
|
||||
let hdl = spawn(async move {
|
||||
let next_batch = timeline_stream.next().await.unwrap();
|
||||
// There can be more than three updates because we add things like
|
||||
// date dividers and implicit read receipts
|
||||
|
||||
@@ -332,6 +332,7 @@ mod test {
|
||||
use assert_matches2::{assert_let, assert_matches};
|
||||
use futures_util::{join, StreamExt};
|
||||
use matrix_sdk_base::crypto::types::{qr_login::QrCodeModeData, SecretsBundle};
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use matrix_sdk_test::async_test;
|
||||
use serde_json::json;
|
||||
|
||||
@@ -469,7 +470,7 @@ mod test {
|
||||
let login_bob = oauth.login_with_qr_code(&qr_code, Some(®istration_data));
|
||||
let mut updates = login_bob.subscribe_to_progress();
|
||||
|
||||
let updates_task = tokio::spawn(async move {
|
||||
let updates_task = spawn(async move {
|
||||
let mut sender = Some(sender);
|
||||
|
||||
while let Some(update) = updates.next().await {
|
||||
@@ -487,7 +488,7 @@ mod test {
|
||||
}
|
||||
});
|
||||
let alice_task =
|
||||
tokio::spawn(async { grant_login(alice, receiver, AliceBehaviour::HappyPath).await });
|
||||
spawn(async { grant_login(alice, receiver, AliceBehaviour::HappyPath).await });
|
||||
|
||||
join!(
|
||||
async {
|
||||
@@ -557,7 +558,7 @@ mod test {
|
||||
let login_bob = oauth.login_with_qr_code(&qr_code, Some(®istration_data));
|
||||
let mut updates = login_bob.subscribe_to_progress();
|
||||
|
||||
let _updates_task = tokio::spawn(async move {
|
||||
let _updates_task = spawn(async move {
|
||||
let mut sender = Some(sender);
|
||||
|
||||
while let Some(update) = updates.next().await {
|
||||
@@ -574,8 +575,7 @@ mod test {
|
||||
}
|
||||
}
|
||||
});
|
||||
let _alice_task =
|
||||
tokio::spawn(async move { grant_login(alice, receiver, alice_behavior).await });
|
||||
let _alice_task = spawn(async move { grant_login(alice, receiver, alice_behavior).await });
|
||||
login_bob.await
|
||||
}
|
||||
|
||||
@@ -681,7 +681,7 @@ mod test {
|
||||
let login_bob = oauth.login_with_qr_code(&qr_code, Some(®istration_data));
|
||||
let mut updates = login_bob.subscribe_to_progress();
|
||||
|
||||
let _updates_task = tokio::spawn(async move {
|
||||
let _updates_task = spawn(async move {
|
||||
let mut sender = Some(sender);
|
||||
|
||||
while let Some(update) = updates.next().await {
|
||||
@@ -699,9 +699,7 @@ mod test {
|
||||
}
|
||||
});
|
||||
let _alice_task =
|
||||
tokio::spawn(
|
||||
async move { grant_login(alice, receiver, AliceBehaviour::HappyPath).await },
|
||||
);
|
||||
spawn(async move { grant_login(alice, receiver, AliceBehaviour::HappyPath).await });
|
||||
let error = login_bob.await.unwrap_err();
|
||||
|
||||
assert_matches!(
|
||||
|
||||
@@ -234,6 +234,7 @@ pub(super) mod test {
|
||||
};
|
||||
|
||||
use matrix_sdk_base::crypto::types::qr_login::QrCodeMode;
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use matrix_sdk_test::async_test;
|
||||
use serde_json::json;
|
||||
use similar_asserts::assert_eq;
|
||||
@@ -358,7 +359,7 @@ pub(super) mod test {
|
||||
|
||||
let qr_code_data = alice.qr_code_data().clone();
|
||||
|
||||
let bob_task = tokio::spawn(async move {
|
||||
let bob_task = spawn(async move {
|
||||
EstablishedSecureChannel::from_qr_code(
|
||||
reqwest::Client::new(),
|
||||
&qr_code_data,
|
||||
@@ -368,7 +369,7 @@ pub(super) mod test {
|
||||
.expect("Bob should be able to fully establish the secure channel.")
|
||||
});
|
||||
|
||||
let alice_task = tokio::spawn(async move {
|
||||
let alice_task = spawn(async move {
|
||||
alice
|
||||
.connect()
|
||||
.await
|
||||
|
||||
@@ -261,6 +261,7 @@ mod tests {
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use matrix_sdk_test::{async_test, test_json};
|
||||
use wiremock::{
|
||||
matchers::{method, path},
|
||||
@@ -302,7 +303,7 @@ mod tests {
|
||||
.mount(&server)
|
||||
.await;
|
||||
|
||||
let bg_task = tokio::spawn(async move {
|
||||
let bg_task = spawn(async move {
|
||||
futures_util::future::join_all((0..10).map(|_| client.whoami())).await
|
||||
});
|
||||
|
||||
@@ -346,7 +347,7 @@ mod tests {
|
||||
.mount(&server)
|
||||
.await;
|
||||
|
||||
let bg_task = tokio::spawn(async move {
|
||||
let bg_task = spawn(async move {
|
||||
futures_util::future::join_all((0..254).map(|_| client.whoami())).await
|
||||
});
|
||||
|
||||
|
||||
@@ -898,6 +898,7 @@ mod tests {
|
||||
use event_listener::Listener;
|
||||
use futures_util::{future::join_all, pin_mut, StreamExt};
|
||||
use matrix_sdk_base::{RequestedRequiredStates, RoomMemberships};
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use matrix_sdk_test::{async_test, event_factory::EventFactory, ALICE};
|
||||
use ruma::{
|
||||
api::client::error::ErrorKind,
|
||||
@@ -2506,7 +2507,7 @@ mod tests {
|
||||
pin_mut!(stream);
|
||||
|
||||
let cloned_sync = sliding_sync.clone();
|
||||
tokio::spawn(async move {
|
||||
spawn(async move {
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
|
||||
cloned_sync
|
||||
|
||||
@@ -47,6 +47,7 @@ use std::{
|
||||
use axum::{body::Body, response::IntoResponse, routing::any_service};
|
||||
use http::{header, HeaderValue, Method, Request, StatusCode};
|
||||
use matrix_sdk_base::{boxed_into_future, locks::Mutex};
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use rand::{thread_rng, Rng};
|
||||
use tokio::{net::TcpListener, sync::oneshot};
|
||||
use tower::service_fn;
|
||||
@@ -200,7 +201,7 @@ impl LocalServerBuilder {
|
||||
.into_future();
|
||||
|
||||
// Spawn the server.
|
||||
tokio::spawn(server);
|
||||
spawn(server);
|
||||
|
||||
Ok((
|
||||
uri,
|
||||
|
||||
@@ -14,6 +14,7 @@ use matrix_sdk::{
|
||||
Client, Error, MemoryStore, StateChanges, StateStore,
|
||||
};
|
||||
use matrix_sdk_base::{sync::RoomUpdates, RoomState};
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use matrix_sdk_test::{
|
||||
async_test, sync_state_event,
|
||||
test_json::{
|
||||
@@ -438,14 +439,15 @@ async fn test_request_encryption_event_before_sending() {
|
||||
.mount(&server)
|
||||
.await;
|
||||
|
||||
let first_handle = tokio::spawn({
|
||||
let first_handle = spawn({
|
||||
let room = room.to_owned();
|
||||
async move { room.to_owned().latest_encryption_state().await.map(|state| state.is_encrypted()) }
|
||||
});
|
||||
|
||||
let second_handle = tokio::spawn(async move {
|
||||
room.latest_encryption_state().await.map(|state| state.is_encrypted())
|
||||
});
|
||||
let second_handle =
|
||||
spawn(
|
||||
async move { room.latest_encryption_state().await.map(|state| state.is_encrypted()) },
|
||||
);
|
||||
|
||||
let first_encrypted =
|
||||
first_handle.await.unwrap().expect("We should be able to test if the room is encrypted.");
|
||||
|
||||
@@ -14,6 +14,7 @@ use matrix_sdk::{
|
||||
test_utils::mocks::MatrixMockServer,
|
||||
};
|
||||
use matrix_sdk_base::{EncryptionState, RoomMembersUpdate, RoomState};
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use matrix_sdk_test::{
|
||||
async_test,
|
||||
event_factory::EventFactory,
|
||||
@@ -528,7 +529,7 @@ async fn test_fetch_members_deduplication() {
|
||||
// Create N tasks that try to fetch the members.
|
||||
for _ in 0..5 {
|
||||
#[allow(unknown_lints, clippy::redundant_async_block)] // false positive
|
||||
let task = tokio::spawn({
|
||||
let task = spawn({
|
||||
let room = room.clone();
|
||||
async move { room.sync_members().await }
|
||||
});
|
||||
@@ -612,7 +613,7 @@ async fn test_subscribe_to_typing_notifications() {
|
||||
let room = server.sync_joined_room(&client, room_id).await;
|
||||
|
||||
// Send to typing notification
|
||||
let join_handle = tokio::spawn({
|
||||
let join_handle = spawn({
|
||||
let typing_sequences = Arc::clone(&typing_sequences);
|
||||
async move {
|
||||
let (_drop_guard, mut subscriber) = room.subscribe_to_typing_notifications();
|
||||
|
||||
@@ -16,6 +16,7 @@ use matrix_sdk::{
|
||||
},
|
||||
Client,
|
||||
};
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use ratatui::{
|
||||
prelude::*,
|
||||
widgets::{Block, Borders, Clear, List, ListItem, ListState, Paragraph},
|
||||
@@ -94,7 +95,7 @@ impl DefaultRecoveryView {
|
||||
let backup_state = client.encryption().backups().state();
|
||||
let backup_exists = Arc::new(AtomicBool::default());
|
||||
|
||||
let backup_update_task = tokio::spawn({
|
||||
let backup_update_task = spawn({
|
||||
let client = client.clone();
|
||||
let backup_exists = backup_exists.clone();
|
||||
|
||||
@@ -119,12 +120,11 @@ impl DefaultRecoveryView {
|
||||
let client = self.client.clone();
|
||||
|
||||
if matches!(self.recovery_state, RecoveryState::Disabled) {
|
||||
let enable_task =
|
||||
tokio::spawn(async move { client.encryption().recovery().enable().await });
|
||||
let enable_task = spawn(async move { client.encryption().recovery().enable().await });
|
||||
|
||||
self.mode = Mode::Enabling { enable_task, throbber_state: ThrobberState::default() };
|
||||
} else {
|
||||
let disable_task = tokio::spawn(async move {
|
||||
let disable_task = spawn(async move {
|
||||
// TODO: Handle errors here?
|
||||
let _ = client.encryption().recovery().disable().await;
|
||||
Ok(())
|
||||
|
||||
@@ -6,6 +6,7 @@ use matrix_sdk::{
|
||||
ruma::api::client::uiaa::{AuthData, Password},
|
||||
Client,
|
||||
};
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use ratatui::{
|
||||
prelude::*,
|
||||
widgets::{Block, Paragraph},
|
||||
@@ -152,7 +153,7 @@ impl RecoveringView {
|
||||
.expect("We should have access to our user ID if we're resetting our identity")
|
||||
.to_owned();
|
||||
|
||||
let reset_task = tokio::spawn(async move {
|
||||
let reset_task = spawn(async move {
|
||||
let handle = client.encryption().recovery().reset_identity().await?;
|
||||
|
||||
if let Some(handle) = handle {
|
||||
@@ -245,7 +246,7 @@ impl RecoveringView {
|
||||
let recovery_key = recovery_text_area.lines().join("");
|
||||
let client = self.client.clone();
|
||||
|
||||
let recovery_task = tokio::spawn(async move {
|
||||
let recovery_task = spawn(async move {
|
||||
client.encryption().recovery().recover(recovery_key.trim()).await
|
||||
});
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ http.workspace = true
|
||||
json-structural-diff = "0.1.0"
|
||||
matrix-sdk = { workspace = true, default-features = true, features = ["testing", "qrcode"] }
|
||||
matrix-sdk-base = { workspace = true, default-features = true, features = ["testing", "qrcode"] }
|
||||
matrix-sdk-common.workspace = true
|
||||
matrix-sdk-test.workspace = true
|
||||
matrix-sdk-ui = { workspace = true, default-features = true }
|
||||
once_cell.workspace = true
|
||||
|
||||
@@ -10,6 +10,7 @@ use matrix_sdk::{
|
||||
},
|
||||
Client, Room, RoomMemberships, RoomState, StateStoreExt,
|
||||
};
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use tokio::sync::Notify;
|
||||
|
||||
use crate::helpers::TestClientBuilder;
|
||||
@@ -31,7 +32,7 @@ async fn test_repeated_join_leave() -> Result<()> {
|
||||
// Sync after 1 second to so that create_room receives the event it is waiting
|
||||
// for.
|
||||
let peter_clone = peter.clone();
|
||||
tokio::spawn(async move {
|
||||
spawn(async move {
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
peter_clone.sync_once(Default::default()).await
|
||||
});
|
||||
@@ -44,7 +45,7 @@ async fn test_repeated_join_leave() -> Result<()> {
|
||||
|
||||
// Continuously sync karl from now on.
|
||||
let karl_clone = karl.clone();
|
||||
let join_handle = tokio::spawn(async move {
|
||||
let join_handle = spawn(async move {
|
||||
karl_clone.sync(Default::default()).await.unwrap();
|
||||
});
|
||||
let invite_signal = Arc::new(Notify::new());
|
||||
|
||||
Reference in New Issue
Block a user