Actors
Learn how to use actors and the actor model in XState and Stately Studio.
Actors
When you run a state machine, it becomes an actor: a running process that can receive events, send events and change its behavior based on the events it receives, which can cause effects outside of the actor.
State machine actors
State machine actors are actors whose logic is represented by a finite state machine or statechart.
Promise actors
Promise actors are actors that represent a promise that performs some asynchronous task. They may resolve with some output, or reject with an error.
Transition Actors
Transition actors are actors whose logic is represented by a state-transition function, which is a function that returns the next state of an actor given:
Callback Actors
Callback actors are actors whose logic is represented by a function that can "callback" to the parent actor by sending events (via sendBack(...)). It can also receive(...) events from other actors.
Observable Actors
Observable actors are actors that represent an observable stream of values. This makes it easy to interop with observable libraries like RxJS.
Invoke
State machines can “invoke” one or many actors within a given state. The invoked actor will start when the state is entered, and stop when the state is exited. Any XState actor can be invoked, including simple Promise-based actors, or even complex machine-based actors.
Spawn
You can use spawn to run actors. Actors created with spawn are spawning actors, and actors created with invoke are invoking actors.
Systems
An actor system is a collection of actors that can communicate with each other. Actors can invoke/spawn other actors, which forms a natural hierarchy of actors that belong to the same system.
Inspection
The Inspect API is a way to inspect the state transitions of your state machines and every aspect of actors in an actor system. Including: