agourlay / dlm

Minimal HTTP download manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Potential issue with finish_all method ?

vikigenius opened this issue · comments

I was going through the source and found something confusing.

Here is the current finish_all method

pub async fn finish_all(&self) -> Result<(), DlmError> {
for _ in 0..self.file_pb_count {
let pb = self.rx.recv().await?;
pb.finish();
}
self.main_pb.finish();
Ok(())
}

I am confused. Shouldn't it be max_concurrent_downloads instead of file_pb_count ? Because at most max_concurrent_downloads progress bars are being created ?

Hi @vikigenius,

Thank you for checking the source, I remember you from Reddit 👍
I understand why you are confused, the code could be improved.

Currently file_pb_count is set to max_concurrent_downloads in ProgressBarManager::init.
This means dlm always create max_concurrent_downloads progress bars eagerly even if the input file contains less entries, which means having progress bars that are never used being displayed.

Ideally we should initialize file_pb_count with min(max_concurrent_downloads, input_file_len).

This would be an easy PR if you want to contribute.

Is this answering your question?

Ah ok that makes sense, sure I will make a PR.