diff --git a/examples/message_log.rs b/examples/message_log.rs index 44a63801..10895f33 100644 --- a/examples/message_log.rs +++ b/examples/message_log.rs @@ -1,4 +1,4 @@ -use std::{env, process::exit}; +use std::{env, process::exit, time::Duration}; use futures_util::stream::{StreamExt as _, TryStreamExt as _}; use ruma_client::{ @@ -21,11 +21,18 @@ async fn log_messages( client.log_in(username, password, None, None).await?; - // TODO: This is a horrible way to obtain an initial next_batch token that generates way too - // much server load and network traffic. Fix this! - - // Skip initial sync reponse vvvvvvvv - let mut sync_stream = Box::pin(client.sync(None, None, SetPresence::Online).skip(1)); + let mut sync_stream = Box::pin( + client + .sync( + None, + None, + SetPresence::Online, + Some(Duration::from_secs(30)), + ) + // TODO: This is a horrible way to obtain an initial next_batch token that generates way + // too much server load and network traffic. Fix this! + .skip(1), + ); while let Some(res) = sync_stream.try_next().await? { // Only look at rooms the user hasn't left yet diff --git a/src/lib.rs b/src/lib.rs index a3948ef1..ff1c39af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,12 +29,20 @@ //! events), use the `Client::sync`: //! //! ```no_run +//! use std::time::Duration; +//! //! # use futures_util::stream::{StreamExt as _, TryStreamExt as _}; //! # use ruma_client::{api::r0::sync::sync_events::SetPresence, Client}; //! # let homeserver_url = "https://example.com".parse().unwrap(); //! # let client = Client::https(homeserver_url, None); +//! # let next_batch_token = String::new(); //! # async { -//! let mut sync_stream = Box::pin(client.sync(None, None, SetPresence::Online)); +//! let mut sync_stream = Box::pin(client.sync( +//! None, +//! Some(next_batch_token), +//! SetPresence::Online, +//! Some(Duration::from_secs(30)), +//! )); //! while let Some(response) = sync_stream.try_next().await? { //! // Do something with the data in the response... //! } @@ -86,6 +94,7 @@ use std::{ convert::TryFrom, str::FromStr, sync::{Arc, Mutex}, + time::Duration, }; use futures_core::{ @@ -298,6 +307,7 @@ where filter: Option, since: Option, set_presence: api::r0::sync::sync_events::SetPresence, + timeout: Option, ) -> impl Stream> + TryStream { use api::r0::sync::sync_events; @@ -314,7 +324,7 @@ where since, full_state: false, set_presence, - timeout: None, + timeout, }) .await?;