use std::time::Duration;
use tokio::time::Instant;
use crate::behavior::Address;
use crate::{Crash, Exit};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TimerId(pub u64);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TimerGeneration(pub u64);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ScheduleAt {
pub id: TimerId,
pub generation: TimerGeneration,
pub at: Instant,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ScheduleAfter {
pub id: TimerId,
pub generation: TimerGeneration,
pub after: Duration,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TimerElapsed {
pub id: TimerId,
pub generation: TimerGeneration,
}
pub trait TimeEvent: Sized {
fn time_reached(event: TimerElapsed) -> Option<Self>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ObservePeer<A> {
pub peer: A,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PeerStopped<A: Address> {
pub peer: A,
pub outcome: Result<Exit<A>, Crash>,
}
pub trait PeerEvent<A: Address>: Sized {
fn peer_stopped(event: PeerStopped<A>) -> Option<Self>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ChildStopped<A: Address> {
pub nonce: A::Nonce,
pub outcome: Result<Exit<A>, Crash>,
pub at: Instant,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ObserveChild<A: Address> {
pub nonce: A::Nonce,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReportWorkerStopped<A: Address> {
pub outcome: Result<Exit<A>, Crash>,
pub at: Instant,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WorkerStopped<A: Address> {
pub proxy: A::Nonce,
pub outcome: Result<Exit<A>, Crash>,
pub at: Instant,
}
pub trait ChildEvent<A: Address>: Sized {
fn child_stopped(event: ChildStopped<A>) -> Option<Self>;
}
pub trait WorkerEvent<A: Address>: Sized {
fn worker_stopped(event: WorkerStopped<A>) -> Option<Self>;
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct ShutdownRequested;
pub trait ShutdownEvent: Sized {
fn shutdown_requested(event: ShutdownRequested) -> Option<Self>;
}