Skip to content

Commit

Permalink
Make Accounts::background_fetch() not return Result
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt authored and r10s committed Jan 31, 2024
1 parent f7fd1ef commit d6c24eb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
16 changes: 4 additions & 12 deletions deltachat-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4915,19 +4915,11 @@ pub unsafe extern "C" fn dc_accounts_background_fetch(
let accounts = &*accounts;
block_on(async move {
let accounts = accounts.read().await;
match accounts
accounts
.background_fetch(Duration::from_secs(timeout_in_seconds))
.await
{
Ok(()) => 1,
Err(err) => {
accounts.emit_event(EventType::Error(format!(
"Failed to do background fetch: {err:#}"
)));
0
}
}
})
.await;
});
1
}

#[no_mangle]
Expand Down
5 changes: 2 additions & 3 deletions deltachat-jsonrpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,15 @@ impl CommandApi {

/// Performs a background fetch for all accounts in parallel with a timeout.
///
/// The `AccountsBackgroundFetchDone` event is emitted at the end
/// if the method returns sucessfully, even in case of timeout.
/// The `AccountsBackgroundFetchDone` event is emitted at the end 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
.write()
.await
.background_fetch(std::time::Duration::from_secs_f64(timeout_in_seconds))
.await?;
.await;
Ok(())
}

Expand Down
5 changes: 1 addition & 4 deletions src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ 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<()> {
pub async fn background_fetch(&self, timeout: std::time::Duration) {
if let Err(_err) =
tokio::time::timeout(timeout, self.background_fetch_without_timeout()).await
{
Expand All @@ -328,7 +326,6 @@ impl Accounts {
));
}
self.emit_event(EventType::AccountsBackgroundFetchDone);
Ok(())
}

/// Emits a single event.
Expand Down

0 comments on commit d6c24eb

Please sign in to comment.