Skip to content

Commit

Permalink
trying rayon for threads
Browse files Browse the repository at this point in the history
  • Loading branch information
404salad committed Sep 5, 2024
1 parent 53d22bd commit 75f5744
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
46 changes: 46 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 @@ -9,5 +9,6 @@ edition = "2021"
console = "0.15.8"
notify = "6.1.1"
pulldown-cmark = "0.9.3"
rayon = "1.10.0"
serde = { version="1.0.196", features = ["derive"] }
toml = "0.8.10"
27 changes: 11 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod consolidate_into_homepage;
pub mod parse_one_article;
pub mod utils;

use rayon::prelude::*;
use std::fs;
use std::thread;
use std::time::Duration;
Expand Down Expand Up @@ -39,23 +40,17 @@ fn main() {

// rebuilding all the articles in content directory (parallely)

for article_name in article_names {
article_names.par_iter().for_each(|article_name| {
let user_config_for_threads = user_config.clone();
let parse_handler = thread::spawn(move || {
match parse_one_article::markdown_to_styled_html(
&article_name,
&user_config_for_threads,
) {
Ok(_) => {
println!("succesful parse")
}
Err(e) => {
eprintln!("unsuccesful parse {}", e)
}
};
});
let res = parse_handler.join();
}
match parse_one_article::markdown_to_styled_html(&article_name, &user_config_for_threads) {
Ok(_) => {
println!("succesful parse")
}
Err(e) => {
eprintln!("unsuccesful parse {}", e)
}
}
});

match consolidate_into_homepage::create_homepage(&user_config) {
Ok(_) => {
Expand Down

0 comments on commit 75f5744

Please sign in to comment.