Actors (spawn v2.0.0-RC13)

View Source

Actors It's the client API for the Spawn actors. Through this module we interact with the actors by creating, invoking or configuring them.

Summary

Functions

Makes a request to an actor.

Makes a request to an actor using Nats broker.

Performs a liveness check for a given actor.

Performs a readiness check for a given actor.

Registers all actors defined in HostActor.

Spawn actors defined in HostActor.

Functions

get_state(id)

@spec get_state(Spawn.Actors.ActorId.t()) :: {:ok, term()} | {:error, term()}

See Actors.Actor.CallerProducer.get_state/1.

invoke(request, opts \\ [])

Makes a request to an actor.

  • request - The InvocationRequest
  • opts - The options to Invoke Actors ##

invoke_with_nats(request, opts \\ [])

@spec invoke_with_nats(Spawn.InvocationRequest.t(), Keyword.t()) ::
  {:ok, :async} | {:ok, term()} | {:error, term()}

Makes a request to an actor using Nats broker.

  • request - The InvocationRequest
  • opts - The options to Invoke Actors ##

liveness(id)

@spec liveness(Spawn.Actors.ActorId.t()) :: {:ok, term()} | {:error, term()}

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(id)

@spec readiness(Spawn.Actors.ActorId.t()) :: {:ok, term()} | {:error, term()}

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 all actors defined in HostActor.

  • registration - The RegistrationRequest
  • opts - The options to create Actors ##

spawn_actor(spawn, opts \\ [])

@spec spawn_actor(Spawn.SpawnRequest.t(), any()) :: {:ok, Spawn.SpawnResponse.t()}

Spawn actors defined in HostActor.

  • registration - The SpawnRequest
  • opts - The options to create Actors

spawn_actor must be used when you want to create a concrete instance of an actor previously registered as unnamed. That is, when an Actorid is associated with an actor of unnamed type. This function only registers the metadata of the new actor, not activating it. This will occur when the sprite is first invoked. ##