View Source Actors.Actor.CallerProducer (spawn v2.0.0-RC11)
Actors.Actor.CallerProducer
This module defines a GenStage producer responsible for managing actor-related operations such as retrieving actor state, actor registration, actor spawning, and actor invocation.
Client API
The client API provides functions for interacting with actors. These functions can be used to initiate operations such as getting actor state, registering actors, spawning new actors, and invoking actors.
Functions
start_link/1
: Starts the CallerProducer process.get_state/2
: Retrieves the state of a specified actor.register/2
: Registers an actor with the specified registration request.spawn_actor/2
: Spawns an actor based on the specified spawn request.invoke/2
: Invokes an actor with the specified invocation request.enqueue/1
: Enqueues an event for processing.
Server API
The server API includes functions that handle the GenStage behavior. These functions manage the state and processing of events.
Functions
init/1
: Initializes the GenStage process.handle_demand/2
: Handles demand requests from consumers.handle_call/3
: Handles call requests from consumers.handle_cast/2
: Handles cast requests from consumers.
Usage
To interact with this module, use the client API functions provided. These functions handle backpressure if enabled in the configuration.
Summary
Functions
Enqueues an event for processing.
Retrieves the state of a specified actor.
Invokes an actor with the specified invocation request.
Performs a liveness check for a given actor.
Performs a readiness check for a given actor.
Registers an actor with the specified registration request.
Spawns an actor based on the specified spawn request.
Starts the CallerProducer process.
Functions
Enqueues an event for processing.
Parameters
event
(any): The event to be enqueued.
Retrieves the state of a specified actor.
Parameters
actor_id
(ActorId.t()): The ID of the actor.opts
(any): Additional options.
Returns
{:ok, state}
: If the state is successfully retrieved.{:error, reason}
: If an error occurs during the operation.
Invokes an actor with the specified invocation request.
Parameters
request
(InvocationRequest.t()): The invocation request.opts
(any): Additional options.
Returns
{:ok, :async}
: If the invocation is asynchronous.{:ok, result}
: If the invocation is successful.{:error, reason}
: If an error occurs during the invocation.
Performs a liveness check for a given actor.
Parameters
actor_id
(ActorId.t()): The ID of the actor.opts
(any): Additional options.
Returns
{:ok, response}
: If the response is successfully.{:error, reason}
: If an error occurs during the operation.
Performs a readiness check for a given actor.
Parameters
actor_id
(ActorId.t()): The ID of the actor.opts
(any): Additional options.
Returns
{:ok, response}
: If the response is successfully.{:error, reason}
: If an error occurs during the operation.
@spec register(Spawn.RegistrationRequest.t(), any()) :: {:ok, Spawn.RegistrationResponse.t()} | {:error, Spawn.RegistrationResponse.t()}
Registers an actor with the specified registration request.
Parameters
registration
(RegistrationRequest.t()): The registration request.opts
(any): Additional options.
Returns
{:ok, response}
: If the actor is successfully registered.{:error, response}
: If an error occurs during the registration.
@spec spawn_actor(Spawn.SpawnRequest.t(), any()) :: {:ok, Spawn.SpawnResponse.t()}
Spawns an actor based on the specified spawn request.
Parameters
spawn_req
(SpawnRequest.t()): The spawn request.opts
(any): Additional options.
Returns
{:ok, response}
: If the actor is successfully spawned.{:error, response}
: If an error occurs during the spawning.
Starts the CallerProducer process.
Parameters
state
(any): Initial state for the process.
Returns
:ignore
: If the process is already running.{:error, reason}
: If an error occurs during process initialization.{:ok, pid}
: If the process starts successfully.