src/client/http_client.rs - BackupReader: use async

This commit is contained in:
Dietmar Maurer 2019-09-04 13:57:05 +02:00
parent 9d456cf8ec
commit d4a085e564
1 changed files with 21 additions and 20 deletions

View File

@ -497,55 +497,55 @@ impl BackupReader {
Arc::new(Self { h2, canceller: canceller }) Arc::new(Self { h2, canceller: canceller })
} }
pub fn get( pub async fn get(
&self, &self,
path: &str, path: &str,
param: Option<Value>, param: Option<Value>,
) -> impl Future<Output = Result<Value, Error>> { ) -> Result<Value, Error> {
self.h2.get(path, param) self.h2.get(path, param).await
} }
pub fn put( pub async fn put(
&self, &self,
path: &str, path: &str,
param: Option<Value>, param: Option<Value>,
) -> impl Future<Output = Result<Value, Error>> { ) -> Result<Value, Error> {
self.h2.put(path, param) self.h2.put(path, param).await
} }
pub fn post( pub async fn post(
&self, &self,
path: &str, path: &str,
param: Option<Value>, param: Option<Value>,
) -> impl Future<Output = Result<Value, Error>> { ) -> Result<Value, Error> {
self.h2.post(path, param) self.h2.post(path, param).await
} }
pub fn download<W: Write + Send + 'static>( pub async fn download<W: Write + Send>(
&self, &self,
file_name: &str, file_name: &str,
output: W, output: W,
) -> impl Future<Output = Result<W, Error>> { ) -> Result<W, Error> {
let path = "download"; let path = "download";
let param = json!({ "file-name": file_name }); let param = json!({ "file-name": file_name });
self.h2.download(path, Some(param), output) self.h2.download(path, Some(param), output).await
} }
pub fn speedtest<W: Write + Send + 'static>( pub async fn speedtest<W: Write + Send>(
&self, &self,
output: W, output: W,
) -> impl Future<Output = Result<W, Error>> { ) -> Result<W, Error> {
self.h2.download("speedtest", None, output) self.h2.download("speedtest", None, output).await
} }
pub fn download_chunk<W: Write + Send + 'static>( pub async fn download_chunk<W: Write + Send>(
&self, &self,
digest: &[u8; 32], digest: &[u8; 32],
output: W, output: W,
) -> impl Future<Output = Result<W, Error>> { ) -> Result<W, Error> {
let path = "chunk"; let path = "chunk";
let param = json!({ "digest": digest_to_hex(digest) }); let param = json!({ "digest": digest_to_hex(digest) });
self.h2.download(path, Some(param), output) self.h2.download(path, Some(param), output).await
} }
pub fn force_close(self) { pub fn force_close(self) {
@ -1105,12 +1105,12 @@ impl H2Client {
self.request(req) self.request(req)
} }
pub fn download<W: Write + Send + 'static>( pub async fn download<W: Write + Send>(
&self, &self,
path: &str, path: &str,
param: Option<Value>, param: Option<Value>,
output: W, output: W,
) -> impl Future<Output = Result<W, Error>> { ) -> Result<W, Error> {
let request = Self::request_builder("localhost", "GET", path, param).unwrap(); let request = Self::request_builder("localhost", "GET", path, param).unwrap();
self.send_request(request, None) self.send_request(request, None)
@ -1143,6 +1143,7 @@ impl H2Client {
} }
}) })
}) })
.await
} }
pub fn upload( pub fn upload(