From c18fddf80fb625bda1a2962d0a5a5acbc4893887 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 5 Sep 2019 14:16:45 +0200 Subject: [PATCH] src/client/http_client.rs - download_chunk_list: simplify async code --- src/client/http_client.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/client/http_client.rs b/src/client/http_client.rs index 0701e661..75bb9d06 100644 --- a/src/client/http_client.rs +++ b/src/client/http_client.rs @@ -851,14 +851,15 @@ impl BackupClient { let mut body = resp.into_body(); let mut release_capacity = body.release_capacity().clone(); - DigestListDecoder::new(body.map_err(Error::from)) - .try_for_each(move |chunk| { - let _ = release_capacity.release_capacity(chunk.len()); - println!("GOT DOWNLOAD {}", digest_to_hex(&chunk)); - known_chunks.lock().unwrap().insert(chunk); - futures::future::ok(()) - }) - .await + let mut stream = DigestListDecoder::new(body.map_err(Error::from)); + + while let Some(chunk) = stream.try_next().await? { + let _ = release_capacity.release_capacity(chunk.len()); + println!("GOT DOWNLOAD {}", digest_to_hex(&chunk)); + known_chunks.lock().unwrap().insert(chunk); + } + + Ok(()) } fn upload_chunk_info_stream(