fix subscriptions: channel size and ContentLength error

This commit is contained in:
edouardparis 2025-02-04 10:39:17 +01:00
parent 8c800a275c
commit 178f818284
2 changed files with 9 additions and 9 deletions

View File

@ -22,9 +22,7 @@ pub fn file<I: 'static + Hash + Copy + Send + Sync, T: ToString>(
fn download(url: String) -> impl Stream<Item = Result<Progress, DownloadError>> {
try_channel(100, move |mut output| async move {
let response = reqwest::get(&url).await?;
let total = response
.content_length()
.ok_or(DownloadError::NoContentLength)?;
let total = response.content_length();
let _ = output.send(Progress::Downloading(0.0)).await;
@ -37,11 +35,13 @@ fn download(url: String) -> impl Stream<Item = Result<Progress, DownloadError>>
downloaded += chunk.len();
bytes.append(&mut chunk.to_vec());
let _ = output
.send(Progress::Downloading(
100.0 * downloaded as f32 / total as f32,
))
.await;
if let Some(total) = total {
let _ = output
.send(Progress::Downloading(
100.0 * downloaded as f32 / total as f32,
))
.await;
}
}
let _ = output.send(Progress::Finished(bytes)).await;

View File

@ -328,7 +328,7 @@ impl Loader {
}
fn get_bitcoind_log(log_path: PathBuf) -> impl Stream<Item = Option<String>> {
channel(1, move |mut output| async move {
channel(5, move |mut output| async move {
loop {
// Reduce the io load.
tokio::time::sleep(Duration::from_millis(500)).await;