From 2c9ae8f389c5108fe33d10f6c2c86d3a4b8d9388 Mon Sep 17 00:00:00 2001 From: f00wl Date: Wed, 13 Dec 2023 19:43:53 +0100 Subject: [PATCH] feat: add optional sync timeout --- Readme.md | 1 + src/main.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 90e05ba..986e257 100644 --- a/Readme.md +++ b/Readme.md @@ -34,6 +34,7 @@ you can provide custom homeservers, too. It will start with a full-sync of the room state, so depending on the size of your matrix account(s), this may take a moment. +Optional `timeout` (in seconds) can be added. ## Changelog **Unreleased** diff --git a/src/main.rs b/src/main.rs index a5a53c8..a86276d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,6 +40,10 @@ struct Args { #[arg(long, env = "TO_HOMESERVER")] to_homeserver: Option, + /// Custom timeout for syncing, default is 10 secs + #[arg(long, env = "TIMEOUT")] + timeout: Option, + /// Custom logging info #[arg(long, env = "RUST_LOG", default_value = "matrix_migrate=info")] log: String, @@ -85,11 +89,16 @@ async fn main() -> anyhow::Result<()> { info!("All logged in. Syncing..."); + let sync_settings = if let Some(s) = args.timeout { + SyncSettings::default().timeout(Duration::from_secs(s)) + } else { + SyncSettings::default() + }; let to_c_stream = to_c.clone(); - let to_sync_stream = to_c_stream.sync_stream(SyncSettings::default()).await; + let to_sync_stream = to_c_stream.sync_stream(sync_settings.clone()).await; pin_mut!(to_sync_stream); - try_join!(from_c.sync_once(SyncSettings::default()), async { + try_join!(from_c.sync_once(sync_settings.clone()), async { to_sync_stream.next().await.unwrap() })?;