Report imex and configure success/failure after freeing ongoing

Otherwise it's possible that library user (e.g. test)
tries to start another ongoing process when previous one is
not freed yet.
This commit is contained in:
link2xt
2022-06-20 16:45:09 +00:00
parent 7ce291fac5
commit 377fa01e98
3 changed files with 18 additions and 23 deletions

View File

@@ -12,6 +12,7 @@
- python: avoid exceptions when messages/contacts/chats are compared with `None`
- node: wait for the event loop to stop before destroying contexts #3431
- emit configuration errors via event on failure #3433
- report configure and imex success/failure after freeing ongoing process #3442
### API-Changes
- python: added `Message.get_status_updates()` #3416

View File

@@ -75,6 +75,8 @@ impl Context {
}))
.await;
self.free_ongoing().await;
if let Err(err) = res.as_ref() {
progress!(
self,
@@ -93,8 +95,6 @@ impl Context {
progress!(self, 1000);
}
self.free_ongoing().await;
res
}

View File

@@ -86,30 +86,24 @@ pub async fn imex(
) -> Result<()> {
let cancel = context.alloc_ongoing().await?;
let res = async {
let success = imex_inner(context, what, path, passphrase).await;
match success {
Ok(()) => {
info!(context, "IMEX successfully completed");
context.emit_event(EventType::ImexProgress(1000));
Ok(())
}
Err(err) => {
// We are using Anyhow's .context() and to show the inner error, too, we need the {:#}:
error!(context, "{:#}", err);
context.emit_event(EventType::ImexProgress(0));
bail!("IMEX FAILED to complete: {}", err);
}
}
}
.race(async {
cancel.recv().await.ok();
Err(format_err!("canceled"))
})
.await;
let res = imex_inner(context, what, path, passphrase)
.race(async {
cancel.recv().await.ok();
Err(format_err!("canceled"))
})
.await;
context.free_ongoing().await;
if let Err(err) = res.as_ref() {
// We are using Anyhow's .context() and to show the inner error, too, we need the {:#}:
error!(context, "IMEX failed to complete: {:#}", err);
context.emit_event(EventType::ImexProgress(0));
} else {
info!(context, "IMEX successfully completed");
context.emit_event(EventType::ImexProgress(1000));
}
res
}