pub struct System { /* private fields */ }Expand description
A running actor system.
Implementations§
Source§impl System
impl System
Sourcepub fn initialize(
logic: &SystemLogic,
options: InitOptions,
) -> Result<(Self, Vec<ExternalEffect>), SystemError>
pub fn initialize( logic: &SystemLogic, options: InitOptions, ) -> Result<(Self, Vec<ExternalEffect>), SystemError>
XState’s initialSystemTransition: allocates and starts the root.
Returns the system and the external effects produced.
Sourcepub fn root_address(&self) -> &Arc<str> ⓘ
pub fn root_address(&self) -> &Arc<str> ⓘ
System::root, shared.
Sourcepub fn next_deadline(&self) -> Option<u64>
pub fn next_deadline(&self) -> Option<u64>
The earliest pending deadline.
Sourcepub fn try_clone(&self) -> Option<Self>
pub fn try_clone(&self) -> Option<Self>
A copy of the system, with its own snapshots, and the logic and
effects’ implementations shared: what crate::Actor::apply keeps
to undo a chunk. None when an actor’s snapshot cannot be copied
(AnySnapshot::clone_box), as one of logic outside this crate.
Sourcepub fn external_effects(&self) -> impl Iterator<Item = &ExternalEffect>
pub fn external_effects(&self) -> impl Iterator<Item = &ExternalEffect>
Pending external work, by id.
Sourcepub fn actor_ref(&self, address: &str) -> Option<ActorRef>
pub fn actor_ref(&self, address: &str) -> Option<ActorRef>
The current reference of the actor at address.
Sourcepub fn logic(&self) -> &SystemLogic
pub fn logic(&self) -> &SystemLogic
The logic the system was created with.
Sourcepub fn actor_src(&self, address: &str) -> Option<&str>
pub fn actor_src(&self, address: &str) -> Option<&str>
The src of the actor at address: the path of its logic, as
root/actors/fetchUser, or root for the root.
Sourcepub fn actor_logic(
&self,
address: &str,
) -> Option<(Option<String>, Option<&Value>)>
pub fn actor_logic( &self, address: &str, ) -> Option<(Option<String>, Option<&Value>)>
The logic id (Logic::logic_id: for async logic, the name it was
registered under) and the input of the actor at address.
Sourcepub fn snapshot(&self, address: &str) -> Option<&dyn AnySnapshot>
pub fn snapshot(&self, address: &str) -> Option<&dyn AnySnapshot>
The snapshot of the actor at address.
Sourcepub fn check(
&self,
address: &str,
event: &Value,
) -> Result<TransitionCheck, SystemError>
pub fn check( &self, address: &str, event: &Value, ) -> Result<TransitionCheck, SystemError>
What the actor at address would do with event, as XState’s
snapshot.check(event) (Logic::check), at the system’s current
time (no due timer fires). Nothing changes: the event is not sent,
no action runs and no actor is created.
Sourcepub fn handles(&self, address: &str, event: &Value) -> Result<bool, SystemError>
pub fn handles(&self, address: &str, event: &Value) -> Result<bool, SystemError>
Whether the actor at address selects a transition of event (see
Logic::handles): false of an actor with no snapshot.
Sourcepub fn fire_next_timer(
&mut self,
time: u64,
) -> Result<Option<Vec<ExternalEffect>>, SystemError>
pub fn fire_next_timer( &mut self, time: u64, ) -> Result<Option<Vec<ExternalEffect>>, SystemError>
Fires only the earliest timer occurrence due at or before time (the
clock moves to its due time), as a live actor processes each timer
as its own step. Returns None when no timer is due.
Sourcepub fn advance(&mut self, time: u64) -> Result<Vec<ExternalEffect>, SystemError>
pub fn advance(&mut self, time: u64) -> Result<Vec<ExternalEffect>, SystemError>
XState’s advanceSystemTime: fires every timer due at or before
time, chronologically, then sets the clock to time.
Sourcepub fn send(
&mut self,
address: &str,
event: Value,
) -> Result<Vec<ExternalEffect>, SystemError>
pub fn send( &mut self, address: &str, event: Value, ) -> Result<Vec<ExternalEffect>, SystemError>
XState’s systemTransition: delivers event to the actor at
address and completes all resulting work. Due timers fire first.
Sourcepub fn resolve_effect(
&mut self,
effect_id: &str,
event: Option<Value>,
) -> Result<Vec<ExternalEffect>, SystemError>
pub fn resolve_effect( &mut self, effect_id: &str, event: Option<Value>, ) -> Result<Vec<ExternalEffect>, SystemError>
Acknowledges external work, optionally delivering its result to the
actor that requested it (xstate.system.effect.result).
Sourcepub fn acknowledge(&mut self, effect_id: &str) -> bool
pub fn acknowledge(&mut self, effect_id: &str) -> bool
Retires pending external work without delivering a result (an
xstate.system.effect.result without event). Returns whether it
was pending.
Sourcepub fn from_json(
logic: &SystemLogic,
data: &Value,
max_steps: usize,
) -> Result<Self, SystemError>
pub fn from_json( logic: &SystemLogic, data: &Value, max_steps: usize, ) -> Result<Self, SystemError>
Restores a system from System::to_json data and the same logic.
Source§impl System
impl System
Sourcepub fn view(&self) -> SystemView<'_>
pub fn view(&self) -> SystemView<'_>
The system snapshot as a SystemView: serializes to the same data
as System::to_json, without building it.
Sourcepub fn compact_view(&self) -> SystemView<'_>
pub fn compact_view(&self) -> SystemView<'_>
A smaller snapshot that System::from_json restores to the same
system: XState’s SystemSnapshot without the fields restore rebuilds
identically when they are missing (empty collections, the default
execution id, actor addresses, which are the keys of actors, and in
machine snapshots the state value, derived from nodeIds, and
empty children, historyValue, timers and stateInputs). It is
not meant for XState’s own restore.