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
58
59
#![warn(missing_docs)]
mod actors;
pub mod prime;
metacrate::meta!();
use actors::supervisor::NodeSupervisor;
use anyhow::Error;
use meio::thread;
use once_cell::sync::Lazy;
use std::sync::Mutex;
static GLOBAL: Lazy<Mutex<Option<RillRate>>> = Lazy::new(|| Mutex::new(None));
pub struct RillRate {
_rt: thread::ScopedRuntime,
}
impl RillRate {
pub fn start(_name: impl ToString) -> Result<Self, Error> {
let actor = NodeSupervisor::new(Default::default());
let rt = thread::spawn(actor)?;
Ok(RillRate { _rt: rt })
}
pub fn pin(self) -> Result<(), Error> {
let mut opt_handle = GLOBAL.lock().map_err(|err| Error::msg(err.to_string()))?;
*opt_handle = Some(self);
Ok(())
}
pub fn install(name: impl ToString) -> Result<(), Error> {
Self::start(name)?.pin()
}
pub fn uninstall() -> Result<(), Error> {
let mut opt_handle = GLOBAL.lock().map_err(|err| Error::msg(err.to_string()))?;
opt_handle.take();
Ok(())
}
}
pub fn install(name: impl ToString) -> Result<(), Error> {
RillRate::install(name)
}
pub fn uninstall() -> Result<(), Error> {
RillRate::uninstall()
}