ref(jsonrpc): Getting backup provider QR code now blocks (#4198)

This changes the JSON-RPC APIs to get a QR code from the backup
provider to block.  It means once you have a (blocking) call to
provide_backup() you can call get_backup_qr() or get_backup_qr_svg()
and they will block until the QR code is available.

Calling get_backup_qr() or get_backup_qr_svg() when there is no backup
provider will immediately error.
This commit is contained in:
Floris Bruynooghe
2023-03-22 12:45:38 +01:00
committed by GitHub
parent 7ec3a1a9a2
commit e985588c6c
3 changed files with 107 additions and 54 deletions

View File

@@ -126,16 +126,14 @@ impl BackupProvider {
let handle = {
let context = context.clone();
tokio::spawn(async move {
let res = Self::watch_provider(&context, provider, cancel_token, dbfile).await;
let res = Self::watch_provider(&context, provider, cancel_token).await;
context.free_ongoing().await;
paused_guard.resume().await;
drop(dbfile);
res
})
};
let slf = Self { handle, ticket };
let qr = slf.qr();
*context.export_provider.lock().expect("poisoned lock") = Some(qr);
Ok(slf)
Ok(Self { handle, ticket })
}
/// Creates the provider task.
@@ -189,7 +187,6 @@ impl BackupProvider {
context: &Context,
mut provider: Provider,
cancel_token: Receiver<()>,
_dbfile: TempPathGuard,
) -> Result<()> {
// _dbfile exists so we can clean up the file once it is no longer needed
let mut events = provider.subscribe();
@@ -255,11 +252,6 @@ impl BackupProvider {
},
}
};
context
.export_provider
.lock()
.expect("poisoned lock")
.take();
match &res {
Ok(_) => context.emit_event(SendProgress::Completed.into()),
Err(err) => {