use crate::Moirai;
use moirai_core::{
error::ExecutorResult,
executor::{ExecutorConfig, WorkerPlacement},
};
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 worker_placement(mut self, placement: WorkerPlacement) -> Self {
self.config.worker_placement = placement;
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 local_queue_initial_capacity(mut self, size: usize) -> Self {
self.config.local_queue_initial_capacity = size;
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()
}
}