Skip to content

Commit f7fd1ef

Browse files
link2xtr10s
authored andcommitted
Emit DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE even on timeout
Otherwise if there is a timeout, UI will wait for DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE forever.
1 parent af7bf5b commit f7fd1ef

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

deltachat-ffi/deltachat.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,15 +3157,14 @@ void dc_accounts_maybe_network_lost (dc_accounts_t* accounts);
31573157
*
31583158
* dc_accounts_background_fetch() was created for the iOS Background fetch.
31593159
*
3160-
* The `DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE` event is emitted at the end,
3161-
* process all events until you get this one and you can safely return to the background
3160+
* The `DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE` event is emitted at the end
3161+
* even in case of timeout, unless the function fails and returns 0.
3162+
* Process all events until you get this one and you can safely return to the background
31623163
* without forgetting to create notifications caused by timing race conditions.
31633164
*
31643165
* @memberof dc_accounts_t
31653166
* @param timeout The timeout in seconds
3166-
* @return Return 1 on success and 0 on failure (like timeout)
3167-
* But note that this only indicates that the fetch of all accounts was done before the timeout.
3168-
* To know whether it worked you need to look for the events.
3167+
* @return Return 1 if DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE was emitted and 0 otherwise.
31693168
*/
31703169
int dc_accounts_background_fetch (dc_accounts_t* accounts, uint64_t timeout);
31713170

deltachat-jsonrpc/src/api.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,9 @@ impl CommandApi {
233233

234234
/// Performs a background fetch for all accounts in parallel with a timeout.
235235
///
236-
/// The `AccountsBackgroundFetchDone` event is emitted at the end,
237-
/// process all events until you get this one and you can safely return to the background
236+
/// The `AccountsBackgroundFetchDone` event is emitted at the end
237+
/// if the method returns sucessfully, even in case of timeout.
238+
/// Process all events until you get this one and you can safely return to the background
238239
/// without forgetting to create notifications caused by timing race conditions.
239240
async fn accounts_background_fetch(&self, timeout_in_seconds: f64) -> Result<()> {
240241
self.accounts

src/accounts.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,18 @@ impl Accounts {
317317
/// The `AccountsBackgroundFetchDone` event is emitted at the end,
318318
/// process all events until you get this one and you can safely return to the background
319319
/// without forgetting to create notifications caused by timing race conditions.
320+
///
321+
/// On error no `AccountsBackgroundFetchDone` event is emitted.
320322
pub async fn background_fetch(&self, timeout: std::time::Duration) -> Result<()> {
321-
let result = tokio::time::timeout(timeout, self.background_fetch_without_timeout()).await;
323+
if let Err(_err) =
324+
tokio::time::timeout(timeout, self.background_fetch_without_timeout()).await
325+
{
326+
self.emit_event(EventType::Warning(
327+
"Background fetch timed out.".to_string(),
328+
));
329+
}
322330
self.emit_event(EventType::AccountsBackgroundFetchDone);
323-
result.map_err(|err| err.into())
331+
Ok(())
324332
}
325333

326334
/// Emits a single event.

0 commit comments

Comments
 (0)