Skip to main content

palladium_runtime/
common.rs

1use crate::reactor::Reactor;
2use palladium_actor::{
3    ActorError, ActorPath, AddrHash, ChildSpec, Envelope, MessagePayload, StopReason,
4};
5use std::time::Duration;
6
7/// Commands sent from actor code (via `RuntimeBridgeImpl`) to the actor's own
8/// event loop.  Processed after each `on_message` returns.
9pub(crate) enum ActorCmd<R: Reactor> {
10    /// Actor called `ctx.spawn(spec)`; forward to supervisor.
11    Spawn {
12        spec: ChildSpec<R>,
13        parent: ActorPath,
14    },
15    /// Actor called `ctx.stop()`.
16    Stop,
17    /// Actor called `ctx.send_after(delay, ...)`.
18    SendAfter {
19        delay: Duration,
20        envelope: Envelope,
21        payload: MessagePayload,
22    },
23}
24
25/// Events flowing from actor/supervisor tasks up to their parent supervisor.
26pub(crate) enum ChildEvent<R: Reactor> {
27    /// `on_start` completed successfully.
28    #[allow(dead_code)]
29    Started,
30    /// `on_start` returned `Err` or panicked.
31    StartFailed {
32        addr: AddrHash,
33        #[allow(dead_code)]
34        error: ActorError,
35    },
36    /// `on_message` returned `Err` or panicked.
37    MessageFailed {
38        addr: AddrHash,
39        #[allow(dead_code)]
40        error: ActorError,
41    },
42    /// Actor called `on_stop`; task is about to exit.
43    Stopped {
44        addr: AddrHash,
45        #[allow(dead_code)]
46        reason: StopReason,
47    },
48    /// Actor called `ctx.spawn(spec)` — supervisor must spawn the child.
49    SpawnRequest {
50        spec: ChildSpec<R>,
51        parent: ActorPath,
52    },
53}
54
55/// Lifecycle signals from supervisor to actor (higher priority than user msgs).
56#[derive(Debug, Clone)]
57pub enum LifecycleSignal<R: Reactor> {
58    Stop(StopReason),
59    SpawnChild(ChildSpec<R>),
60}