src/bin/upload-speed.rs: switch to async

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-08-29 09:58:20 +02:00
parent cab6816969
commit 8630557918

View File

@ -1,9 +1,8 @@
use failure::*;
use futures::*;
use proxmox_backup::client::*;
fn upload_speed() -> Result<usize, Error> {
async fn upload_speed() -> Result<usize, Error> {
let host = "localhost";
let datastore = "store2";
@ -14,28 +13,22 @@ fn upload_speed() -> Result<usize, Error> {
let backup_time = chrono::Utc::now();
let client = client.start_backup(datastore, "host", "speedtest", backup_time, false).wait()?;
let client = client.start_backup(datastore, "host", "speedtest", backup_time, false).await?;
println!("start upload speed test");
let res = client.upload_speedtest().wait()?;
let res = client.upload_speedtest().await?;
Ok(res)
}
fn main() {
let mut rt = tokio::runtime::Runtime::new().unwrap();
// should be rt.block_on_all, but this block forever in release builds
let _ = rt.block_on(futures::future::lazy(move || -> Result<(), ()> {
match upload_speed() {
Ok(mbs) => {
println!("average upload speed: {} MB/s", mbs);
}
Err(err) => {
eprintln!("ERROR: {}", err);
}
#[tokio::main]
async fn main() {
match upload_speed().await {
Ok(mbs) => {
println!("average upload speed: {} MB/s", mbs);
}
Ok(())
}));
Err(err) => {
eprintln!("ERROR: {}", err);
}
}
}