Context object providing actor communication and scheduling capabilities. More...
#include <actor.hpp>
Classes | |
| struct | TAsync |
| Helper class for managing asynchronous operations in actors. More... | |
Public Types | |
| using | TPtr = std::unique_ptr<TActorContext> |
Public Member Functions | |
| TActorId | Sender () const |
| Get the sender of the current message. | |
| TActorId | Self () const |
| Get this actor's ID. | |
| void | Send (TActorId to, TMessageId messageId, TBlob blob) |
| Send a message to another actor. | |
| void | Forward (TActorId to, TMessageId messageId, TBlob blob) |
| Forward a message to another actor (preserves original sender). | |
| template<typename T, typename... Args> | |
| void | Send (TActorId to, Args &&... args) |
| Send a typed message to another actor (non-blocking). | |
| template<typename T, typename... Args> | |
| void | Forward (TActorId to, Args &&... args) |
| Forward a typed message to another actor, preserving the original sender. | |
| void | SendAs (TActorId from, TActorId to, TMessageId messageId, TBlob blob) |
| Send a message with an explicitly specified sender. | |
| template<typename T, typename... Args> | |
| void | SendAs (TActorId from, TActorId to, Args &&... args) |
| Send a typed message with an explicitly specified sender. | |
| TEvent | Schedule (TTime when, TActorId sender, TActorId recipient, TMessageId messageId, TBlob blob) |
| Schedule a message to be delivered at a specific time. | |
| template<typename T, typename... Args> | |
| TEvent | Schedule (TTime when, TActorId sender, TActorId recipient, Args &&... args) |
| Schedule a typed message to be delivered at a specific time. | |
| void | Cancel (TEvent event) |
| Cancel a previously scheduled message. | |
| TActorId | Register (std::unique_ptr< IActor > actor) |
| Registers a new actor in the same actor system. | |
| TFuture< void > | Sleep (TTime until) |
| Suspend the current handler until a specific time. | |
| template<typename Rep, typename Period> | |
| TFuture< void > | Sleep (std::chrono::duration< Rep, Period > duration) |
| Suspend the current handler for a duration. | |
| template<typename T, typename TQuestion> | |
| TFuture< T > | Ask (TActorId recipient, TQuestion &&question) |
| Send a request and suspend until a reply of type T arrives. | |
| TAsync | StartAsync () |
| Start an asynchronous operation context. | |
Static Public Member Functions | |
| static void * | operator new (size_t)=delete |
| static void * | operator new (size_t size, TActorSystem *actorSystem) |
| static void | operator delete (void *ptr) |
Friends | |
| class | TActorSystem |
| class | TMockActorContext |
Context object providing actor communication and scheduling capabilities.
TActorContext is passed to actors during message dispatch. It provides methods for sending messages, scheduling future messages, sleeping, and performing request-response patterns.
The context is valid only for the duration of the Receive / CoReceive call chain. Capture ctx->Sender() / ctx->Self() by value if you need them after the first co_await.
|
inline |
Send a request and suspend until a reply of type T arrives.
Sends question to recipient and returns a future that resolves to the first reply of type T sent back to this actor. Must be co_await-ed inside ICoroActor::CoReceive or an async TBehavior::Receive.
| T | Expected response message type |
| TQuestion | Question message type |
| recipient | Actor to send the question to |
| question | Message forwarded to the recipient |
| void NNet::NActors::TActorContext::Cancel | ( | TEvent | event | ) |
Cancel a previously scheduled message.
| event | Event handle returned by Schedule() |
|
inline |
Forward a typed message to another actor, preserving the original sender.
Like Send<T>, but the recipient sees ctx->Sender() equal to the sender of the current message rather than this actor's ID. Useful for routing/proxy actors that should not appear in the reply chain.
| T | Message type; must have a static TMessageId MessageId member |
| to | Recipient actor ID |
| args | Constructor arguments forwarded to T |
Forward a message to another actor (preserves original sender).
| to | Recipient actor ID |
| messageId | Message type identifier |
| blob | Serialized message data |
Registers a new actor in the same actor system.
| actor | Actor to register (ownership transferred) |
|
inline |
Schedule a typed message to be delivered at a specific time.
| T | Message type that has MessageId static member |
| when | Time when the message should be delivered |
| sender | Sender actor ID for the scheduled message |
| recipient | Recipient actor ID |
| args | args passed to the Message constructor |
| TEvent NNet::NActors::TActorContext::Schedule | ( | TTime | when, |
| TActorId | sender, | ||
| TActorId | recipient, | ||
| TMessageId | messageId, | ||
| TBlob | blob ) |
Schedule a message to be delivered at a specific time.
| when | Time when the message should be delivered |
| sender | Sender actor ID for the scheduled message |
| recipient | Recipient actor ID |
| messageId | Message type identifier |
| blob | Serialized message data |
|
inline |
Send a typed message to another actor (non-blocking).
Constructs a T in-place from args and enqueues it to the recipient. Returns immediately; delivery is deferred to the next event-loop iteration.
| T | Message type; must have a static TMessageId MessageId member |
| to | Recipient actor ID |
| args | Constructor arguments forwarded to T |
Send a message to another actor.
| to | Recipient actor ID |
| messageId | Message type identifier |
| blob | Serialized message data |
|
inline |
Send a typed message with an explicitly specified sender.
Like Send<T>, but the recipient sees ctx->Sender() equal to from.
| T | Message type; must have a static TMessageId MessageId member |
| from | Actor ID that the recipient will see as ctx->Sender() |
| to | Recipient actor ID |
| args | Constructor arguments forwarded to T |
| void NNet::NActors::TActorContext::SendAs | ( | TActorId | from, |
| TActorId | to, | ||
| TMessageId | messageId, | ||
| TBlob | blob ) |
Send a message with an explicitly specified sender.
| from | Actor ID that the recipient will see as ctx->Sender() |
| to | Recipient actor ID |
| messageId | Message type identifier |
| blob | Serialized message data |
|
inline |
Suspend the current handler for a duration.
Convenience overload for relative delays. Must be co_await-ed.
| Rep | Duration representation type |
| Period | Duration period type |
| duration | How long to sleep |
|
inline |
Suspend the current handler until a specific time.
Must be co_await-ed inside ICoroActor::CoReceive or an async TBehavior::Receive. The actor system continues processing other actors while this handler is suspended.
| until | Absolute time point to wake up at |
| TActorContext::TAsync NNet::NActors::TActorContext::StartAsync | ( | ) |
Start an asynchronous operation context.