use crate::Moirai;
use moirai_core::{error::ExecutorResult, executor::ExecutorConfig};
use moirai_executor::HybridExecutor;
use std::sync::Arc;
pub struct MoiraiBuilder {
config: ExecutorConfig,
}
impl MoiraiBuilder {
#[must_use]
pub fn new() -> Self {
Self {
config: ExecutorConfig::default(),
}
}
#[must_use]
pub fn worker_threads(mut self, count: usize) -> Self {
self.config.worker_threads = count;
self
}
#[must_use]
pub fn async_threads(mut self, count: usize) -> Self {
self.config.async_threads = count;
self
}
#[must_use]
pub fn max_global_queue_size(mut self, size: usize) -> Self {
self.config.max_global_queue_size = size;
self
}
#[must_use]
pub fn max_local_queue_size(mut self, size: usize) -> Self {
self.config.max_local_queue_size = size;
self
}
#[cfg(feature = "numa")]
#[must_use]
pub fn numa_aware(self, enabled: bool) -> Self {
let _ = enabled; self
}
#[must_use]
pub fn thread_name_prefix(mut self, prefix: impl Into<String>) -> Self {
self.config.thread_name_prefix = prefix.into();
self
}
#[cfg(feature = "metrics")]
#[must_use]
pub fn enable_metrics(self, enabled: bool) -> Self {
let _ = enabled; self
}
pub fn build(self) -> ExecutorResult<Moirai> {
let executor = HybridExecutor::new(self.config)?;
Ok(Moirai {
executor: Arc::new(executor),
})
}
}
impl Default for MoiraiBuilder {
fn default() -> Self {
Self::new()
}
}