Skip to content

Commit

Permalink
wip: blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
oneofthezombies committed Feb 12, 2024
1 parent 19e7ca9 commit 4b7e72b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
15 changes: 2 additions & 13 deletions crates/libs/kill_tree/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ pub(crate) mod tokio {

#[instrument]
pub(crate) async fn get_process_infos() -> Result<ProcessInfos> {
let mut tasks: ::tokio::task::JoinSet<Result<ProcessInfo>> = ::tokio::task::JoinSet::new();
let mut read_dir = ::tokio::fs::read_dir("/proc").await?;
let mut process_infos = ProcessInfos::new();
while let Some(entry) = read_dir.next_entry().await? {
let file_name = entry.file_name();
let Some(file_name) = file_name.to_str() else {
Expand All @@ -229,18 +229,7 @@ pub(crate) mod tokio {
continue;
}
};
tasks.spawn(get_process_info(process_id, entry.path()));
}
let mut process_infos = ProcessInfos::new();
while let Some(join_result) = tasks.join_next().await {
let result = join_result?;
let process_info = match result {
Ok(x) => x,
Err(e) => {
debug!(error = ?e, "Failed to get process info");
continue;
}
};
let process_info = get_process_info(process_id, entry.path()).await?;
process_infos.push(process_info);
}
Ok(process_infos)
Expand Down
8 changes: 4 additions & 4 deletions test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ main();

// linux
// blocking
// Total elapsed time: 1325ms
// Mean elapsed time: 1.325ms
// Total elapsed time: 1318ms
// Mean elapsed time: 1.318ms
// tokio
// Total elapsed time: 6285ms
// Mean elapsed time: 6.285ms
// Total elapsed time: 6291ms
// Mean elapsed time: 6.291ms

// macos
// blocking
Expand Down

0 comments on commit 4b7e72b

Please sign in to comment.