1use std::time::Duration;
8
9use tokio::time::Instant;
10
11use crate::behavior::Address;
12use crate::{Crash, Exit};
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
15pub struct TimerId(pub u64);
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18pub struct TimerGeneration(pub u64);
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub struct ScheduleAt {
22 pub id: TimerId,
23 pub generation: TimerGeneration,
24 pub at: Instant,
25}
26
27#[derive(Debug, Clone, Copy, PartialEq, Eq)]
33pub struct ScheduleAfter {
34 pub id: TimerId,
35 pub generation: TimerGeneration,
36 pub after: Duration,
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub struct TimerElapsed {
41 pub id: TimerId,
42 pub generation: TimerGeneration,
43}
44
45pub trait TimeEvent: Sized {
46 fn time_reached(event: TimerElapsed) -> Option<Self>;
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50pub struct ObservePeer<A> {
51 pub peer: A,
52}
53
54#[derive(Debug, Clone, PartialEq, Eq)]
55pub struct PeerStopped<A: Address> {
56 pub peer: A,
57 pub outcome: Result<Exit<A>, Crash>,
58}
59
60pub trait PeerEvent<A: Address>: Sized {
61 fn peer_stopped(event: PeerStopped<A>) -> Option<Self>;
62}
63
64#[derive(Debug, Clone, PartialEq, Eq)]
65pub struct ChildStopped<A: Address> {
66 pub nonce: A::Nonce,
67 pub outcome: Result<Exit<A>, Crash>,
68 pub at: Instant,
69}
70
71#[derive(Debug, Clone, Copy, PartialEq, Eq)]
72pub struct ObserveChild<A: Address> {
73 pub nonce: A::Nonce,
74}
75
76#[derive(Debug, Clone, PartialEq, Eq)]
80pub struct ReportWorkerStopped<A: Address> {
81 pub outcome: Result<Exit<A>, Crash>,
82 pub at: Instant,
83}
84
85#[derive(Debug, Clone, PartialEq, Eq)]
87pub struct WorkerStopped<A: Address> {
88 pub proxy: A::Nonce,
89 pub outcome: Result<Exit<A>, Crash>,
90 pub at: Instant,
91}
92
93pub trait ChildEvent<A: Address>: Sized {
94 fn child_stopped(event: ChildStopped<A>) -> Option<Self>;
95}
96
97pub trait WorkerEvent<A: Address>: Sized {
98 fn worker_stopped(event: WorkerStopped<A>) -> Option<Self>;
99}
100
101#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
103pub struct ShutdownRequested;
104
105pub trait ShutdownEvent: Sized {
106 fn shutdown_requested(event: ShutdownRequested) -> Option<Self>;
107}