Skip to content

Commit 43ea3ba

Browse files
authored
Merge pull request #32 from Dr-Emann/simplify_chan
Use channel closing rather than sending None explicitly
2 parents 67a7225 + 153b39a commit 43ea3ba

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/backend.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<T> Backend<T> {
139139

140140
// Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn.
141141
fn compress_loop(&mut self) {
142-
let (send_file, send_file_rx) = bounded::<Option<(PathBuf, u64)>>(1);
142+
let (send_file, send_file_rx) = bounded::<(PathBuf, u64)>(1);
143143
let (recv_result_tx, recv_result) = bounded::<(PathBuf, io::Result<bool>)>(1);
144144

145145
let compression = Some(config().read().unwrap().current().compression);
@@ -209,7 +209,7 @@ impl<T> Backend<T> {
209209

210210
if let Some(mut fi) = folder.pop(FileKind::Compressible) {
211211
send_file
212-
.send(Some((folder.path.join(&fi.path), fi.logical_size)))
212+
.send((folder.path.join(&fi.path), fi.logical_size))
213213
.expect("send_file");
214214

215215
if !displayed && last_update.elapsed() > Duration::from_millis(50) {
@@ -297,7 +297,7 @@ impl<T> Backend<T> {
297297
}
298298
}
299299

300-
send_file.send(None).expect("send_file");
300+
drop(send_file);
301301
task.wait();
302302

303303
let _ = incompressible.save();
@@ -322,7 +322,7 @@ impl<T> Backend<T> {
322322

323323
// Oh no, not again.
324324
fn uncompress_loop(&mut self) {
325-
let (send_file, send_file_rx) = bounded::<Option<(PathBuf, u64)>>(1);
325+
let (send_file, send_file_rx) = bounded::<(PathBuf, u64)>(1);
326326
let (recv_result_tx, recv_result) = bounded::<(PathBuf, io::Result<bool>)>(1);
327327

328328
let compactor = BackgroundCompactor::new(None, send_file_rx, recv_result_tx);
@@ -386,7 +386,7 @@ impl<T> Backend<T> {
386386

387387
if let Some(mut fi) = folder.pop(FileKind::Compressed) {
388388
send_file
389-
.send(Some((folder.path.join(&fi.path), fi.logical_size)))
389+
.send((folder.path.join(&fi.path), fi.logical_size))
390390
.expect("send_file");
391391

392392
let mut waiting = false;
@@ -451,7 +451,7 @@ impl<T> Backend<T> {
451451
}
452452
}
453453

454-
send_file.send(None).expect("send_file");
454+
drop(send_file);
455455
task.wait();
456456

457457
let new_size = folder.physical_size;

src/compression.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ use crate::compact::{self, Compression};
1414
#[derive(Debug)]
1515
pub struct BackgroundCompactor {
1616
compression: Option<Compression>,
17-
files_in: Receiver<Option<(PathBuf, u64)>>,
17+
files_in: Receiver<(PathBuf, u64)>,
1818
files_out: Sender<(PathBuf, io::Result<bool>)>,
1919
}
2020

2121
impl BackgroundCompactor {
2222
pub fn new(
2323
compression: Option<Compression>,
24-
files_in: Receiver<Option<(PathBuf, u64)>>,
24+
files_in: Receiver<(PathBuf, u64)>,
2525
files_out: Sender<(PathBuf, io::Result<bool>)>,
2626
) -> Self {
2727
Self {
@@ -67,16 +67,10 @@ impl Background for BackgroundCompactor {
6767
break;
6868
}
6969

70-
match file {
71-
Some((file, _len)) => {
72-
let ret = handle_file(&file, self.compression);
73-
if self.files_out.send((file, ret)).is_err() {
74-
break;
75-
}
76-
}
77-
None => {
78-
break;
79-
}
70+
let file = file.0;
71+
let ret = handle_file(&file, self.compression);
72+
if self.files_out.send((file, ret)).is_err() {
73+
break;
8074
}
8175
}
8276
}

0 commit comments

Comments
 (0)