use std::sync::Arc;
use super::{Builder, RngSeed, TaskMeta, UnhandledPanic};
impl Builder {
pub fn on_thread_start(mut self, f: impl Fn() + Send + Sync + 'static) -> Self {
self.tuning.hooks.start = Some(Arc::new(f));
self
}
pub fn on_thread_stop(mut self, f: impl Fn() + Send + Sync + 'static) -> Self {
self.tuning.hooks.stop = Some(Arc::new(f));
self
}
pub fn on_thread_park(mut self, f: impl Fn() + Send + Sync + 'static) -> Self {
self.tuning.hooks.park = Some(Arc::new(f));
self
}
pub fn on_thread_unpark(mut self, f: impl Fn() + Send + Sync + 'static) -> Self {
self.tuning.hooks.unpark = Some(Arc::new(f));
self
}
pub fn on_task_spawn(mut self, f: impl Fn(&TaskMeta<'_>) + Send + Sync + 'static) -> Self {
self.task_hooks.spawn = Some(Arc::new(f));
self
}
pub fn on_before_task_poll(
mut self,
f: impl Fn(&TaskMeta<'_>) + Send + Sync + 'static,
) -> Self {
self.task_hooks.before_poll = Some(Arc::new(f));
self
}
pub fn on_after_task_poll(mut self, f: impl Fn(&TaskMeta<'_>) + Send + Sync + 'static) -> Self {
self.task_hooks.after_poll = Some(Arc::new(f));
self
}
pub fn on_task_terminate(mut self, f: impl Fn(&TaskMeta<'_>) + Send + Sync + 'static) -> Self {
self.task_hooks.terminate = Some(Arc::new(f));
self
}
pub fn event_interval(mut self, runs: u32) -> Self {
assert!(runs > 0, "event_interval must be at least 1");
self.tuning.driver_interval = runs;
self
}
pub fn global_queue_interval(mut self, runs: u32) -> Self {
assert!(runs > 0, "global_queue_interval must be at least 1");
self.tuning.inbox_interval = runs;
self
}
pub fn max_io_events_per_tick(mut self, events: usize) -> Self {
assert!(events > 0, "max_io_events_per_tick must be at least 1");
self.tuning.max_io_events = events;
self
}
pub fn disable_lifo_slot(mut self) -> Self {
self.tuning.lifo = false;
self
}
pub fn rng_seed(mut self, seed: RngSeed) -> Self {
self.rng_seed = Some(seed);
self
}
pub fn unhandled_panic(mut self, policy: UnhandledPanic) -> Self {
self.unhandled_panic = policy;
self
}
}