job.rs
This file
Path
src/exec/job.rs
67 lines · 2.1 KiB · Rust
Last changed by
Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e
History of this fileTake it
The walk stopped after 200 commits: lines older than 17d849d point at it.
Merge pull request #1283 from tmccombs/new-rust-versionTavian Barnesbefore adoptione4bca10
line 1why, one step back1use std::sync::Mutex;Compute colors in parallelTavian Barnesbefore adoption17d849d
lines 2–13why, one step back23use crate::config::Config;4use crate::error::print_error;5use crate::exit_codes::{merge_exitcodes, ExitCode};6use crate::walk::WorkerResult;78use super::CommandSet;910/// An event loop that listens for inputs from the `rx` receiver. Each received input will11/// generate a command with the supplied command template. The generated command will then12/// be executed, and this process will continue until the receiver's sender has closed.13pub fn job(Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e
line 14why, one step back14 results: impl IntoIterator<Item = WorkerResult>,Merge pull request #1283 from tmccombs/new-rust-versionTavian Barnesbefore adoptione4bca10
lines 15–16why, one step back15 cmd: &CommandSet,16 out_perm: &Mutex<()>,Compute colors in parallelTavian Barnesbefore adoption17d849d
lines 17–21why, one step back17 config: &Config,18) -> ExitCode {19 // Output should be buffered when only running a single thread20 let buffer_output: bool = config.threads > 1;21Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e
lines 22–23why, one step back22 let mut ret = ExitCode::Success;23 for result in results {Compute colors in parallelTavian Barnesbefore adoption17d849d
lines 24–25why, one step back24 // Obtain the next result from the receiver, else if the channel25 // has closed, exit from the loopMerge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e
lines 26–28why, one step back26 let dir_entry = match result {27 WorkerResult::Entry(dir_entry) => dir_entry,28 WorkerResult::Error(err) => {Compute colors in parallelTavian Barnesbefore adoption17d849d
lines 29–36why, one step back29 if config.show_filesystem_errors {30 print_error(err.to_string());31 }32 continue;33 }34 };3536 // Generate a command, execute it and store its exit code.Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e
line 37why, one step back37 let code = cmd.execute(Compute colors in parallelTavian Barnesbefore adoption17d849d
line 38why, one step back38 dir_entry.stripped_path(config),Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3
line 39why, one step back39 config.path_separator.as_deref(),Merge pull request #1283 from tmccombs/new-rust-versionTavian Barnesbefore adoptione4bca10
line 40why, one step back40 out_perm,Compute colors in parallelTavian Barnesbefore adoption17d849d
line 41why, one step back41 buffer_output,Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e
lines 42–43why, one step back42 );43 ret = merge_exitcodes([ret, code]);Compute colors in parallelTavian Barnesbefore adoption17d849d
lines 44–45why, one step back44 }45 // Returns error in case of any error.Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e
line 46why, one step back46 retCompute colors in parallelTavian Barnesbefore adoption17d849d
lines 47–48why, one step back47}48Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e
lines 49–54why, one step back49pub fn batch(50 results: impl IntoIterator<Item = WorkerResult>,51 cmd: &CommandSet,52 config: &Config,53) -> ExitCode {54 let paths = resultsCompute colors in parallelTavian Barnesbefore adoption17d849d
lines 55–65why, one step back55 .into_iter()56 .filter_map(|worker_result| match worker_result {57 WorkerResult::Entry(dir_entry) => Some(dir_entry.into_stripped_path(config)),58 WorkerResult::Error(err) => {59 if config.show_filesystem_errors {60 print_error(err.to_string());61 }62 None63 }64 });65Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3
line 66why, one step back66 cmd.execute_batch(paths, config.batch_size, config.path_separator.as_deref())Compute colors in parallelTavian Barnesbefore adoption17d849d
line 67why, one step back67}