Hide background_fetch_without_timeout from public API

This commit is contained in:
link2xt
2024-01-29 23:29:57 +00:00
committed by bjoern
parent 5bb80f94c7
commit ea666f1098
3 changed files with 7 additions and 14 deletions

View File

@@ -4916,7 +4916,7 @@ pub unsafe extern "C" fn dc_accounts_background_fetch(
block_on(async move {
let accounts = accounts.read().await;
match accounts
.background_fetch_with_timeout(Duration::from_secs(timeout_in_seconds))
.background_fetch(Duration::from_secs(timeout_in_seconds))
.await
{
Ok(()) => 1,

View File

@@ -240,7 +240,7 @@ impl CommandApi {
self.accounts
.write()
.await
.background_fetch_with_timeout(std::time::Duration::from_secs_f64(timeout_in_seconds))
.background_fetch(std::time::Duration::from_secs_f64(timeout_in_seconds))
.await?;
Ok(())
}

View File

@@ -294,12 +294,9 @@ impl Accounts {
/// Performs a background fetch for all accounts in parallel.
///
/// If you need a timeout, then use [Accounts::background_fetch_with_timeout] instead.
///
/// 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 forgeting to create notifications caused by timing race conditions.
pub async fn background_fetch(&self) {
/// This is an auxiliary function and not part of public API.
/// Use [Accounts::background_fetch] instead.
async fn background_fetch_without_timeout(&self) {
async fn background_fetch_and_log_error(account: Context) {
if let Err(error) = account.background_fetch().await {
warn!(account, "{error:#}");
@@ -313,19 +310,15 @@ impl Accounts {
.map(background_fetch_and_log_error),
)
.await;
self.emit_event(EventType::AccountsBackgroundFetchDone);
}
/// Performs a background fetch for all accounts in parallel with a timeout.
///
/// If you want no timeout, then use [Accounts::background_fetch] instead.
///
/// 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 forgeting to create notifications caused by timing race conditions.
pub async fn background_fetch_with_timeout(&self, timeout: std::time::Duration) -> Result<()> {
let result = tokio::time::timeout(timeout, self.background_fetch()).await;
pub async fn background_fetch(&self, timeout: std::time::Duration) -> Result<()> {
let result = tokio::time::timeout(timeout, self.background_fetch_without_timeout()).await;
self.emit_event(EventType::AccountsBackgroundFetchDone);
result.map_err(|err| err.into())
}