Context object providing actor communication and scheduling capabilities.
More...
#include <actor.hpp>
|
| struct | TAsync |
| | Helper class for managing asynchronous operations in actors. More...
|
| |
|
|
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.
|
| |
| 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.
|
| |
| 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 void * | operator new (size_t size, TActorSystem *actorSystem) |
| |
|
static void | operator delete (void *ptr) |
| |
|
|
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.
- Note
Sleep, Ask, and any coroutine-based methods require co_await and are only meaningful inside ICoroActor::CoReceive or an async TBehavior::Receive (one returning TFuture<void>).
◆ Ask()
template<typename T , typename TQuestion >
| TFuture< T > NNet::NActors::TActorContext::Ask |
( |
TActorId |
recipient, |
|
|
TQuestion && |
question |
|
) |
| |
|
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.
auto reply = co_await ctx->Ask<Pong>(pingActor, Ping{});
- Template Parameters
-
| T | Expected response message type |
| TQuestion | Question message type |
- Parameters
-
| recipient | Actor to send the question to |
| question | Message forwarded to the recipient |
- Returns
- Awaitable future resolving to
T when the reply arrives
◆ Cancel()
| void NNet::NActors::TActorContext::Cancel |
( |
TEvent |
event | ) |
|
Cancel a previously scheduled message.
- Parameters
-
◆ Forward() [1/2]
template<typename T , typename... Args>
| void NNet::NActors::TActorContext::Forward |
( |
TActorId |
to, |
|
|
Args &&... |
args |
|
) |
| |
|
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.
- Template Parameters
-
| T | Message type; must have a static TMessageId MessageId member |
- Parameters
-
| to | Recipient actor ID |
| args | Constructor arguments forwarded to T |
◆ Forward() [2/2]
| void NNet::NActors::TActorContext::Forward |
( |
TActorId |
to, |
|
|
TMessageId |
messageId, |
|
|
TBlob |
blob |
|
) |
| |
Forward a message to another actor (preserves original sender)
- Parameters
-
| to | Recipient actor ID |
| messageId | Message type identifier |
| blob | Serialized message data |
◆ Schedule() [1/2]
template<typename T , typename... Args>
| TEvent NNet::NActors::TActorContext::Schedule |
( |
TTime |
when, |
|
|
TActorId |
sender, |
|
|
TActorId |
recipient, |
|
|
Args &&... |
args |
|
) |
| |
|
inline |
Schedule a typed message to be delivered at a specific time.
- Template Parameters
-
| T | Message type that has MessageId static member |
- Parameters
-
| 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 |
- Returns
- Event handle that can be used to cancel the scheduled message
◆ Schedule() [2/2]
| 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.
- Parameters
-
| 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 |
- Returns
- Event handle that can be used to cancel the scheduled message
◆ Send() [1/2]
template<typename T , typename... Args>
| void NNet::NActors::TActorContext::Send |
( |
TActorId |
to, |
|
|
Args &&... |
args |
|
) |
| |
|
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.
- Template Parameters
-
| T | Message type; must have a static TMessageId MessageId member |
- Parameters
-
| to | Recipient actor ID |
| args | Constructor arguments forwarded to T |
ctx->Send<Pong>(ctx->Sender(), 42);
◆ Send() [2/2]
| void NNet::NActors::TActorContext::Send |
( |
TActorId |
to, |
|
|
TMessageId |
messageId, |
|
|
TBlob |
blob |
|
) |
| |
Send a message to another actor.
- Parameters
-
| to | Recipient actor ID |
| messageId | Message type identifier |
| blob | Serialized message data |
◆ Sleep() [1/2]
template<typename Rep , typename Period >
| TFuture< void > NNet::NActors::TActorContext::Sleep |
( |
std::chrono::duration< Rep, Period > |
duration | ) |
|
|
inline |
Suspend the current handler for a duration.
Convenience overload for relative delays. Must be co_await-ed.
co_await ctx->Sleep(std::chrono::seconds(5));
- Template Parameters
-
| Rep | Duration representation type |
| Period | Duration period type |
- Parameters
-
| duration | How long to sleep |
- Returns
- Awaitable future that resumes after
duration
◆ Sleep() [2/2]
| TFuture< void > NNet::NActors::TActorContext::Sleep |
( |
TTime |
until | ) |
|
|
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.
- Parameters
-
| until | Absolute time point to wake up at |
- Returns
- Awaitable future that resumes at
until
◆ StartAsync()
Start an asynchronous operation context.
- Returns
- TAsync helper for managing the async operation
The documentation for this class was generated from the following files: