Actors.Actor.CallerProducer (spawn v2.0.0-RC14)

View Source

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

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

enqueue(event)

Enqueues an event for processing.

Parameters

  • event (any): The event to be enqueued.

get_state(actor_id, opts \\ [])

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.

invoke(request, opts \\ [])

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.

liveness(actor_id, opts \\ [])

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.

readiness(actor_id, opts \\ [])

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.

register(registration, opts \\ [])

@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.

spawn_actor(spawn_req, opts \\ [])

@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.

start_link(state \\ [])

@spec start_link(any()) :: :ignore | {:error, any()} | {:ok, pid()}

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.