diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index c636521d7..f71010662 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -3157,15 +3157,14 @@ void dc_accounts_maybe_network_lost (dc_accounts_t* accounts); * * dc_accounts_background_fetch() was created for the iOS Background fetch. * - * The `DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE` event is emitted at the end, - * process all events until you get this one and you can safely return to the background + * The `DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE` event is emitted at the end + * even in case of timeout, unless the function fails and returns 0. + * Process all events until you get this one and you can safely return to the background * without forgetting to create notifications caused by timing race conditions. * * @memberof dc_accounts_t * @param timeout The timeout in seconds - * @return Return 1 on success and 0 on failure (like timeout) - * But note that this only indicates that the fetch of all accounts was done before the timeout. - * To know whether it worked you need to look for the events. + * @return Return 1 if DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE was emitted and 0 otherwise. */ int dc_accounts_background_fetch (dc_accounts_t* accounts, uint64_t timeout); diff --git a/deltachat-jsonrpc/src/api.rs b/deltachat-jsonrpc/src/api.rs index c84e95d4b..85cb1c7b6 100644 --- a/deltachat-jsonrpc/src/api.rs +++ b/deltachat-jsonrpc/src/api.rs @@ -233,8 +233,9 @@ impl CommandApi { /// Performs a background fetch for all accounts in parallel with a timeout. /// - /// The `AccountsBackgroundFetchDone` event is emitted at the end, - /// process all events until you get this one and you can safely return to the background + /// The `AccountsBackgroundFetchDone` event is emitted at the end + /// if the method returns sucessfully, even in case of timeout. + /// Process all events until you get this one and you can safely return to the background /// without forgetting to create notifications caused by timing race conditions. async fn accounts_background_fetch(&self, timeout_in_seconds: f64) -> Result<()> { self.accounts diff --git a/src/accounts.rs b/src/accounts.rs index 8c4a73a64..99053719c 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -317,10 +317,18 @@ impl Accounts { /// The `AccountsBackgroundFetchDone` event is emitted at the end, /// process all events until you get this one and you can safely return to the background /// without forgetting to create notifications caused by timing race conditions. + /// + /// On error no `AccountsBackgroundFetchDone` event is emitted. pub async fn background_fetch(&self, timeout: std::time::Duration) -> Result<()> { - let result = tokio::time::timeout(timeout, self.background_fetch_without_timeout()).await; + if let Err(_err) = + tokio::time::timeout(timeout, self.background_fetch_without_timeout()).await + { + self.emit_event(EventType::Warning( + "Background fetch timed out.".to_string(), + )); + } self.emit_event(EventType::AccountsBackgroundFetchDone); - result.map_err(|err| err.into()) + Ok(()) } /// Emits a single event.