1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::io::Result;
use super::{Runtime, Shared};
pub struct Builder {
pub(super) num_threads: usize,
pub(super) thread_stack_size: usize,
pub(super) event_interval: usize,
}
impl Builder {
pub fn new() -> Self {
Self {
num_threads: num_cpus::get(),
thread_stack_size: 2 << 20,
event_interval: 61,
}
}
pub fn num_threads(mut self, num_threads: usize) -> Self {
self.num_threads = num_threads;
self
}
pub fn thread_stack_size(mut self, thread_stack_size: usize) -> Self {
self.thread_stack_size = thread_stack_size;
self
}
pub fn event_interval(mut self, event_interval: usize) -> Self {
self.event_interval = event_interval;
self
}
pub fn build(self) -> Result<Runtime> {
let shared = Shared::new(self)?;
Ok(Runtime(shared))
}
}
impl Default for Builder {
fn default() -> Self {
Self::new()
}
}