COROIO: NNet::NActors::ICoroActor Class Reference
COROIO
 
Loading...
Searching...
No Matches
NNet::NActors::ICoroActor Class Referenceabstract

Coroutine-based actor interface for asynchronous message processing. More...

#include <actor.hpp>

Inheritance diagram for NNet::NActors::ICoroActor:
NNet::NActors::IActor

Public Member Functions

void Receive (TMessageId messageId, TBlob blob, TActorContext::TPtr ctx) override
 IActor bridge — invokes CoReceive and parks pending futures.
 
virtual TFuture< void > CoReceive (TMessageId messageId, TBlob blob, TActorContext::TPtr ctx)=0
 Asynchronous message handler (override in subclass)
 

Additional Inherited Members

- Public Types inherited from NNet::NActors::IActor
using TPtr = std::unique_ptr< IActor >
 

Detailed Description

Coroutine-based actor interface for asynchronous message processing.

Extends IActor so that CoReceive can co_await timers, Ask, or I/O without blocking the event loop thread.

One async handler at a time. When CoReceive returns a pending TFuture<void>, the actor's mailbox is paused: no further messages are dispatched until that future completes. This removes the need for internal locking — state can be mutated freely inside the handler.

class Throttled : public ICoroActor {
TFuture<void> CoReceive(TMessageId id, TBlob blob, TActorContext::TPtr ctx) override {
auto msg = DeserializeNear<Work>(blob);
co_await ctx->Sleep(std::chrono::milliseconds(50)); // next msg waits here
process(msg);
}
};
Coroutine-based actor interface for asynchronous message processing.
Definition actor.hpp:393
Opaque message payload with Near/Far duality.
Definition messages.hpp:99
Owned coroutine handle that carries a result of type T.
Definition corochain.hpp:185

Member Function Documentation

◆ CoReceive()

virtual TFuture< void > NNet::NActors::ICoroActor::CoReceive ( TMessageId  messageId,
TBlob  blob,
TActorContext::TPtr  ctx 
)
pure virtual

Asynchronous message handler (override in subclass)

May freely use co_await ctx->Sleep(...), co_await ctx->Ask<T>(...), or any other coroutine primitive. While this coroutine is suspended, the actor's mailbox is paused — subsequent messages queue up and are delivered only after this handler returns (i.e. its future completes).

Parameters
messageIdType identifier of the incoming message
blobSerialized message payload
ctxActor context (valid for the duration of this handler)
Returns
Future that signals completion of message processing

◆ Receive()

void NNet::NActors::ICoroActor::Receive ( TMessageId  messageId,
TBlob  blob,
TActorContext::TPtr  ctx 
)
overridevirtual

IActor bridge — invokes CoReceive and parks pending futures.

Called by the actor system. Not meant to be overridden; override CoReceive instead.

Implements NNet::NActors::IActor.


The documentation for this class was generated from the following files: