Skip to content

Commit

Permalink
Switch from std::sync::mpsc to crossbeam-channel
Browse files Browse the repository at this point in the history
This lets us avoid rust-lang/rust#39364, which
could potentially be seen now that we're using recv_timeout().
  • Loading branch information
tavianator committed Dec 1, 2021
1 parent 16ae03c commit a4bb734
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dirs-next = "2.0"
normpath = "0.3"
chrono = "0.4"
once_cell = "1.8.0"
crossbeam-channel = "0.5.1"

[dependencies.clap]
version = "2.31.3"
Expand Down
3 changes: 2 additions & 1 deletion src/exec/job.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::path::PathBuf;
use std::sync::mpsc::Receiver;
use std::sync::{Arc, Mutex};

use crossbeam_channel::Receiver;

use crate::error::print_error;
use crate::exit_codes::{merge_exitcodes, ExitCode};
use crate::walk::WorkerResult;
Expand Down
10 changes: 3 additions & 7 deletions src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use std::io;
use std::mem;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::{Duration, Instant};
use std::{borrow::Cow, io::Write};

use anyhow::{anyhow, Result};
use crossbeam_channel::{unbounded, Receiver, RecvTimeoutError, Sender};
use ignore::overrides::OverrideBuilder;
use ignore::{self, WalkBuilder};
use once_cell::unsync::OnceCell;
Expand Down Expand Up @@ -55,7 +55,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<Config>) -> R
let first_path_buf = path_iter
.next()
.expect("Error: Path vector can not be empty");
let (tx, rx) = channel();
let (tx, rx) = unbounded();

let mut override_builder = OverrideBuilder::new(first_path_buf.as_path());

Expand Down Expand Up @@ -219,11 +219,7 @@ impl<W: Write> ReceiverBuffer<W> {
match self.mode {
ReceiverMode::Buffering => {
// Wait at most until we should switch to streaming
let now = Instant::now();
self.deadline
.checked_duration_since(now)
.ok_or(RecvTimeoutError::Timeout)
.and_then(|t| self.rx.recv_timeout(t))
self.rx.recv_deadline(self.deadline)
}
ReceiverMode::Streaming => {
// Wait however long it takes for a result
Expand Down

0 comments on commit a4bb734

Please sign in to comment.