src/api2/backup.rs: switch to async

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-08-28 09:58:39 +02:00
parent 6be147b78c
commit 59b2baa0f6
1 changed files with 15 additions and 6 deletions

View File

@ -106,7 +106,7 @@ fn upgrade_to_backup_protocol(
let env2 = env.clone(); let env2 = env.clone();
let env3 = env.clone(); let env3 = env.clone();
req_body let req_fut = req_body
.on_upgrade() .on_upgrade()
.map_err(Error::from) .map_err(Error::from)
.and_then(move |conn| { .and_then(move |conn| {
@ -121,15 +121,24 @@ fn upgrade_to_backup_protocol(
http.serve_connection(conn, service) http.serve_connection(conn, service)
.map_err(Error::from) .map_err(Error::from)
}) });
.select(abort_future.map_err(|_| {}).then(move |_| { bail!("task aborted"); })) let abort_future = abort_future
.map_err(|(err, _)| err) .map(|_| Err(format_err!("task aborted")));
.and_then(move |(_result, _)| {
use futures::future::Either;
future::select(req_fut, abort_future)
.map(|res| match res {
Either::Left((Ok(res), _)) => Ok(res),
Either::Left((Err(err), _)) => Err(err),
Either::Right((Ok(res), _)) => Ok(res),
Either::Right((Err(err), _)) => Err(err),
})
.and_then(move |_result| async move {
env.ensure_finished()?; env.ensure_finished()?;
env.log("backup finished sucessfully"); env.log("backup finished sucessfully");
Ok(()) Ok(())
}) })
.then(move |result| { .then(move |result| async move {
if let Err(err) = result { if let Err(err) = result {
match env2.ensure_finished() { match env2.ensure_finished() {
Ok(()) => {}, // ignore error after finish Ok(()) => {}, // ignore error after finish