From 119fb101cf117404625e08f6baa4ef09225c5eb8 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Fri, 1 Aug 2025 14:42:36 +0200 Subject: [PATCH] feat: add sys limit --- crates/noworkers/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/noworkers/src/lib.rs b/crates/noworkers/src/lib.rs index 3ac2a26..4a7d976 100644 --- a/crates/noworkers/src/lib.rs +++ b/crates/noworkers/src/lib.rs @@ -3,6 +3,24 @@ use std::{future::Future, sync::Arc}; use tokio::{sync::Mutex, task::JoinHandle}; use tokio_util::sync::CancellationToken; +pub mod extensions { + use crate::Workers; + + pub trait WithSysLimitCpus { + fn with_limit_to_system_cpus(&mut self) -> &mut Self; + } + + impl WithSysLimitCpus for Workers { + fn with_limit_to_system_cpus(&mut self) -> &mut Self { + self.with_limit( + std::thread::available_parallelism() + .expect("to be able to get system cpu info") + .into(), + ) + } + } +} + type ErrChan = Arc< Mutex<( Option>,