mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Refactor loop
into a while
loop.
This commit is contained in:
parent
4618ad6b73
commit
16be0640a8
1 changed files with 3 additions and 6 deletions
|
@ -44,17 +44,14 @@ fn read_block(reader: &mut File) -> Result<ReadStatus, String> {
|
|||
|
||||
fn read_all(reader: &mut File, progress_chan: &ProgressSender, cancel_listener: &CancellationListener)
|
||||
-> Result<LoadResult, String> {
|
||||
loop {
|
||||
if cancel_listener.is_cancelled() {
|
||||
let _ = progress_chan.send(Done(Err("load cancelled".to_owned())));
|
||||
return Ok(LoadResult::Cancelled);
|
||||
}
|
||||
|
||||
while !cancel_listener.is_cancelled() {
|
||||
match try!(read_block(reader)) {
|
||||
ReadStatus::Partial(buf) => progress_chan.send(Payload(buf)).unwrap(),
|
||||
ReadStatus::EOF => return Ok(LoadResult::Finished),
|
||||
}
|
||||
}
|
||||
let _ = progress_chan.send(Done(Err("load cancelled".to_owned())));
|
||||
Ok(LoadResult::Cancelled)
|
||||
}
|
||||
|
||||
fn get_progress_chan(load_data: LoadData, file_path: PathBuf,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue