Skip to content
Myr

Switch from std::sync::mpsc to crossbeam-channel

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This lets us avoid https://github.com/rust-lang/rust/issues/39364, which could potentially be seen now that we're using recv_timeout().

authored by Tavian Barnes · committed by Tavian Barnes · parent 16ae03c · Browse files · 4 files+17 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+17 added−8 removed

  • other:+17 added−8 removed

4 files+17 added−8 removed

modified:src/exec/job.rs+2 added-1 removed
1use std::path::PathBuf;2use std::sync::mpsc::Receiver;2use std::sync::{Arc, Mutex};34use crossbeam_channel::Receiver;56use crate::error::print_error;7use crate::exit_codes::{merge_exitcodes, ExitCode};8use crate::walk::WorkerResult;9
69 unmodified lines
modified:src/walk.rs+3 added-7 removed
2 unmodified lines
3use std::io;4use std::mem;5use std::path::{Path, PathBuf};6use std::sync::atomic::{AtomicBool, Ordering};7use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};7use std::sync::{Arc, Mutex};8use std::thread;9use std::time::{Duration, Instant};10use std::{borrow::Cow, io::Write};1112use anyhow::{anyhow, Result};13use crossbeam_channel::{unbounded, Receiver, RecvTimeoutError, Sender};14use ignore::overrides::OverrideBuilder;15use ignore::{self, WalkBuilder};16use once_cell::unsync::OnceCell;17use regex::bytes::Regex;
36 unmodified lines
54 let mut path_iter = path_vec.iter();55 let first_path_buf = path_iter56 .next()57 .expect("Error: Path vector can not be empty");58 let (tx, rx) = channel();58 let (tx, rx) = unbounded();5960 let mut override_builder = OverrideBuilder::new(first_path_buf.as_path());6162 for pattern in &config.exclude_patterns {
155 unmodified lines
218 fn recv(&self) -> Result<WorkerResult, RecvTimeoutError> {219 match self.mode {220 ReceiverMode::Buffering => {221 // Wait at most until we should switch to streaming222 let now = Instant::now();223 self.deadline224 .checked_duration_since(now)225 .ok_or(RecvTimeoutError::Timeout)226 .and_then(|t| self.rx.recv_timeout(t))222 self.rx.recv_deadline(self.deadline)223 }224 ReceiverMode::Streaming => {225 // Wait however long it takes for a result226 Ok(self.rx.recv()?)
378 unmodified lines
modified:Cargo.lock+11 added
107 unmodified lines
108 "vec_map",109]110111[[package]]112name = "crossbeam-channel"113version = "0.5.1"114source = "registry+https://github.com/rust-lang/crates.io-index"115checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"116dependencies = [117 "cfg-if",118 "crossbeam-utils",119]120121[[package]]122name = "crossbeam-utils"123version = "0.8.5"124source = "registry+https://github.com/rust-lang/crates.io-index"125checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
47 unmodified lines
173 "anyhow",174 "atty",175 "chrono",176 "clap",177 "crossbeam-channel",178 "ctrlc",179 "diff",180 "dirs-next",181 "filetime",
497 unmodified lines
modified:Cargo.toml+1 added