src/bin/upload-speed.rs: switch to async
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
cab6816969
commit
8630557918
@ -1,9 +1,8 @@
|
|||||||
use failure::*;
|
use failure::*;
|
||||||
use futures::*;
|
|
||||||
|
|
||||||
use proxmox_backup::client::*;
|
use proxmox_backup::client::*;
|
||||||
|
|
||||||
fn upload_speed() -> Result<usize, Error> {
|
async fn upload_speed() -> Result<usize, Error> {
|
||||||
|
|
||||||
let host = "localhost";
|
let host = "localhost";
|
||||||
let datastore = "store2";
|
let datastore = "store2";
|
||||||
@ -14,21 +13,17 @@ fn upload_speed() -> Result<usize, Error> {
|
|||||||
|
|
||||||
let backup_time = chrono::Utc::now();
|
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");
|
println!("start upload speed test");
|
||||||
let res = client.upload_speedtest().wait()?;
|
let res = client.upload_speedtest().await?;
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
let mut rt = tokio::runtime::Runtime::new().unwrap();
|
match upload_speed().await {
|
||||||
|
|
||||||
// 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) => {
|
Ok(mbs) => {
|
||||||
println!("average upload speed: {} MB/s", mbs);
|
println!("average upload speed: {} MB/s", mbs);
|
||||||
}
|
}
|
||||||
@ -36,6 +31,4 @@ fn main() {
|
|||||||
eprintln!("ERROR: {}", err);
|
eprintln!("ERROR: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user