diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-07-22 17:34:34 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-07-23 19:22:58 +0300 |
commit | 9a8f4be06cb476b8149ed4f73d2cb62add14873f (patch) | |
tree | 3f6f3c21cfa0bcbdd153dd2c4a80b0c083709600 /src/cmd | |
parent | 34b3e7fe4c1e78ce7c04ba0942c3f5a60db27785 (diff) | |
download | obnam2-9a8f4be06cb476b8149ed4f73d2cb62add14873f.tar.gz |
refactor: use async for "obnam get-chunk"
Sponsored-by: author
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/get_chunk.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/cmd/get_chunk.rs b/src/cmd/get_chunk.rs index 4ee70fe..f574c99 100644 --- a/src/cmd/get_chunk.rs +++ b/src/cmd/get_chunk.rs @@ -1,9 +1,10 @@ use crate::chunkid::ChunkId; -use crate::client::BackupClient; +use crate::client::AsyncBackupClient; use crate::config::ClientConfig; use crate::error::ObnamError; use std::io::{stdout, Write}; use structopt::StructOpt; +use tokio::runtime::Runtime; #[derive(Debug, StructOpt)] pub struct GetChunk { @@ -13,10 +14,14 @@ pub struct GetChunk { impl GetChunk { pub fn run(&self, config: &ClientConfig) -> Result<(), ObnamError> { - let client = BackupClient::new(config)?; - let chunk_id: ChunkId = self.chunk_id.parse().unwrap(); - let chunk = client.fetch_chunk(&chunk_id)?; + let rt = Runtime::new()?; + rt.block_on(self.run_async(config)) + } + async fn run_async(&self, config: &ClientConfig) -> Result<(), ObnamError> { + let client = AsyncBackupClient::new(config)?; + let chunk_id: ChunkId = self.chunk_id.parse().unwrap(); + let chunk = client.fetch_chunk(&chunk_id).await?; let stdout = stdout(); let mut handle = stdout.lock(); handle.write_all(chunk.data())?; |