Skip to main content

libpetri_runtime/
environment.rs

1use std::sync::Arc;
2
3use libpetri_core::token::ErasedToken;
4
5/// An external event to inject into the executor.
6#[derive(Debug, Clone)]
7pub struct ExternalEvent {
8    pub place_name: Arc<str>,
9    pub token: ErasedToken,
10}
11
12/// Signal sent to a running executor via the control channel.
13///
14/// Merges external events and lifecycle commands into a single enum,
15/// avoiding separate channels or atomic flags. The executor's async loop
16/// pattern-matches on these variants with O(1) overhead per iteration.
17///
18/// # Lifecycle signals
19///
20/// - [`Drain`](Self::Drain) — graceful shutdown per \[ENV-011\]: reject new events,
21///   process already-queued events, complete in-flight actions, terminate at quiescence.
22/// - [`Close`](Self::Close) — immediate shutdown per \[ENV-013\]: discard queued events,
23///   complete in-flight actions, terminate.
24///
25/// Use [`ExecutorHandle`](crate::executor_handle::ExecutorHandle) for RAII-managed
26/// lifecycle with automatic drain on drop.
27#[cfg(feature = "tokio")]
28#[derive(Debug)]
29pub enum ExecutorSignal {
30    /// External event injection (existing behavior).
31    Event(ExternalEvent),
32    /// Graceful drain: reject new events, process queued, terminate at quiescence.
33    Drain,
34    /// Immediate close: discard queued events, complete in-flight, terminate.
35    Close,
36}