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::{any::Any, sync::Arc};
use super::{actor::ActorItem, messages::SystemMessage, Sender, ActorError};
#[derive(Clone)]
pub struct Ctx {
internal_sx: Sender<Arc<SystemMessage>>,
}
impl From<Sender<Arc<SystemMessage>>> for Ctx {
fn from(internal_sx: Sender<Arc<SystemMessage>>) -> Self {
Self { internal_sx }
}
}
impl Ctx {
pub fn send_to<T: Any + Send + Sync + 'static>(&self, id: &'static str, msg: T) {
let _ = self
.internal_sx
.send(Arc::new(SystemMessage::SendMsg(id, Box::new(msg))));
}
pub fn shutdown(&self) {
let _ = self.internal_sx.send(Arc::new(SystemMessage::Shutdown));
}
#[allow(dead_code)]
pub fn stop_actor(&self, id: &'static str) {
let _ = self
.internal_sx
.send(Arc::new(SystemMessage::StopActor(id)));
}
#[allow(dead_code)]
pub fn restart_actor(&self, id: &'static str) {
let _ = self
.internal_sx
.send(Arc::new(SystemMessage::RestartActor(id)));
}
pub fn register_actor(&mut self, actor_item: ActorItem) {
let _ = self
.internal_sx
.send(Arc::new(SystemMessage::RegisterActor(actor_item)));
}
pub fn start_actor(&self, id: &'static str) {
let _ = self
.internal_sx
.send(Arc::new(SystemMessage::StartActor(id)));
}
pub fn actor_panicked(&self, id: &'static str) {
let _ = self
.internal_sx
.send(Arc::new(SystemMessage::ActorTaskFinished(id, None)));
}
pub fn actor_returned(&self, id: &'static str, result: Result<(), ActorError>) {
let _ = self
.internal_sx
.send(Arc::new(SystemMessage::ActorTaskFinished(id, Some(result))));
}
}