Struct: TSenderChannel
template <typename T>
struct TSenderChannel;
SPMC (single-prodicer, multiple-consumer) sender channel.
More in-depth explanation of channels can be found in this architecture book page.
Channels are similar to Unreal events, the difference is while channels sends data that gets stored immediatelly on receiver queue, user have to consume received messages by polling (intentionally asking for next message in queue).
The benefit of polling over pushing (Unreal events) is that user has full controll over when and where incoming messages are processed and executed, and that makes user avoid random/undefined data flow which is common pitfall when using events - with channels we bring determinism into the communication between parts of the game.
Note
User can freely send messages across multiple separate threads, for example if user spawn system on another thread to process some big chunk of data and that system has to send it processing results back to game thread.
User might notice there is method for creating bound receiver, but there is none fo destroying it - the reason is receivers are weakly connected so they will automaticall unbound from sender channel as soon as they get destroyed in their scope, and sender will tr to send any message to that already gone receiver.
Example
auto Sender = TSenderChannel<int>();
auto Receiver = Sender.Receiver(1);
Sender.Send(42);
while (const auto Value = Receiver.Receive())
{
UE_LOG(LogTemp, Warning, TEXT("Received value: %i"), Value);
}
Methods
-
Receiver
public: TReceiverChannel<T> Receiver( uint32 Capacity = 0 );
-
Receivers
public: uint32 Receivers() const;
Returns number of actively bound receivers.
-
Send
public: void Send( const T& Data );
Documentation built with Unreal-Doc
v1.0.8 tool by PsichiX