feat: Make the IoPausedGuard a simple sender (#4184)

This replaces the mechanism by which the IoPauseGuard makes sure the
IO scheduler is resumed: it really is a drop guard now by sending a
single message on drop.

This makes it not have to hold on to anything like the context so
makes it a lot easier to use.

The trade-off is that a long-running task is spawned when the guard is
created, this task needs to receive the message from the drop guard in
order for the scheduler to resume.
This commit is contained in:
Floris Bruynooghe
2023-03-22 17:42:21 +01:00
committed by GitHub
parent 89b32e02c5
commit 616eabc613
3 changed files with 33 additions and 37 deletions

View File

@@ -91,15 +91,13 @@ pub async fn imex(
let cancel = context.alloc_ongoing().await?;
let res = {
let mut guard = context.scheduler.pause(context.clone()).await;
let res = imex_inner(context, what, path, passphrase)
let _guard = context.scheduler.pause(context.clone()).await;
imex_inner(context, what, path, passphrase)
.race(async {
cancel.recv().await.ok();
Err(format_err!("canceled"))
})
.await;
guard.resume().await;
res
.await
};
context.free_ongoing().await;