ActorContext

peloton.actor.ActorContext
trait ActorContext[S, M](val currentBehavior: Behavior[S, M])

The actor's context provides some helper functions for its message handler (Behavior)

An instance of the actor context is passed to the actor's message handler, so the handler can use its helper functions.

Type parameters

M

The actor's message base type

S

The type of the actor's internal state

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def respond[R](response: R): IO[Behavior[S, M]]

Send a response back to the sender of this message.

Send a response back to the sender of this message.

Value parameters

response

The response message

Attributes

Returns

The current behavior of the actor.

def setState(newState: S): IO[Behavior[S, M]]

Replace the current state of the actor with a new state.

Replace the current state of the actor with a new state.

Under the hood, the current state might be either stored in memory (like in the StatefulActor) or on a persistent storage (like in PersistentActor).

Value parameters

newState

The new state

Attributes

Returns

The current behavior of the actor.

def stash(): IO[Behavior[S, M]]

Takes the message which is currently processed by the message handler and puts it on the actor's message stash. This allows it to unstash and process the message later, depending on the current state of the actor.

Takes the message which is currently processed by the message handler and puts it on the actor's message stash. This allows it to unstash and process the message later, depending on the current state of the actor.

Attributes

Returns

The current behavior of the actor.

def tellSelf(message: M): IO[Behavior[S, M]]

Send a message of the actor's message type M to the actor which is connected to this context.

Send a message of the actor's message type M to the actor which is connected to this context.

Can be used to seld a message from within the actor's message handler (Behavior) to the same actor. The message will be enqueued at the end of the actor's message queue.

Value parameters

message

A message of the actor's message type M

Attributes

Returns

The current behavior of the actor.

def unstashAll(): IO[Behavior[S, M]]

Moves all messages from the actor's message stash back to the end of the message inbox.

Moves all messages from the actor's message stash back to the end of the message inbox.

Attributes

Returns

The current behavior of the actor.

Concrete methods

inline def !(message: M): IO[Behavior[S, M]]

An alias for tellSelf

An alias for tellSelf

Value parameters

message

A message of the actor's message type M

Attributes

Returns

The current behavior of the actor.

def pipeToSelf[A](effect: IO[A])(mapOutcome: OutcomeIO[A] => IO[List[M]]): IO[FiberIO[Unit]]

Waits asynchronously for the completion/cancellation/abortion of a given effect, transforms the outcome into a list of messages that is compatible with the actor's message type M and sends these messages to the actor.

Waits asynchronously for the completion/cancellation/abortion of a given effect, transforms the outcome into a list of messages that is compatible with the actor's message type M and sends these messages to the actor.

Type parameters

A

The value type of the effect

Value parameters

effect

An effect of type A

mapOutcome

A function that maps the outcome of the evaluation of the given effect to a list of messages of the actor's message type M The cats.effect.Outcome is either

  • Canceled
  • Errored
  • Succeeded.

Attributes

Returns

The fiber of the given effect that has been started in the background, wrapped in an IO effect.

Concrete fields