Skip to main content

agner_test_actor/
query.rs

1use std::convert::Infallible;
2use std::time::Duration;
3
4use agner_actors::{ActorID, Event, Exit};
5use tokio::sync::oneshot;
6
7pub type Tx<T> = oneshot::Sender<T>;
8
9#[derive(Debug)]
10pub enum Query<M> {
11    Exit(ExitRq),
12
13    InitAck(InitAckRq),
14    SetLink(SetLinkRq),
15    SetTrapExit(SetTrapExitRq),
16    NextEvent(NextEventRq<M>),
17}
18
19#[derive(Debug)]
20pub struct InitAckRq {
21    pub value: Option<ActorID>,
22    pub reply_on_drop: Tx<Infallible>,
23}
24
25#[derive(Debug)]
26pub struct SetLinkRq {
27    pub actor: ActorID,
28    pub link: bool,
29    pub reply_on_drop: Tx<Infallible>,
30}
31
32#[derive(Debug)]
33pub struct ExitRq {
34    pub reason: Exit,
35    pub reply_on_drop: Tx<Infallible>,
36}
37
38#[derive(Debug)]
39pub struct SetTrapExitRq {
40    pub set_to: bool,
41    pub reply_on_drop: Tx<Infallible>,
42}
43
44#[derive(Debug)]
45pub struct NextEventRq<M> {
46    pub timeout: Duration,
47    pub reply_to: Tx<Event<M>>,
48}
49
50impl<M> From<InitAckRq> for Query<M> {
51    fn from(inner: InitAckRq) -> Self {
52        Self::InitAck(inner)
53    }
54}
55
56impl<M> From<SetLinkRq> for Query<M> {
57    fn from(inner: SetLinkRq) -> Self {
58        Self::SetLink(inner)
59    }
60}
61impl<M> From<ExitRq> for Query<M> {
62    fn from(inner: ExitRq) -> Self {
63        Self::Exit(inner)
64    }
65}
66impl<M> From<NextEventRq<M>> for Query<M> {
67    fn from(inner: NextEventRq<M>) -> Self {
68        Self::NextEvent(inner)
69    }
70}
71impl<M> From<SetTrapExitRq> for Query<M> {
72    fn from(inner: SetTrapExitRq) -> Self {
73        Self::SetTrapExit(inner)
74    }
75}