MT Core (C++)
Core library for replacing C++ standard in project usage
|
Represents a pub/sub subscription which can receive messages of type T Under the hood, each publisher maintains a message broker which stores all messages Subscribers will hold an Arc to the broker and will retrieve messages from the broker Due to the broker being shared, it does require more locks for both reads and writes This means it has a pretty low throughput when there is lots of contention The primary advantage is it has a much more convenient API for more non-blocking operations or timed blocks The reason this happens is that publishers are given greater insight into each subscription, and can better avoid partial writes. More...
#include <pub_sub.hpp>
Public Types | |
using | Message = T |
Public Member Functions | |
Result< Optional< T >, ChannelTryReceiveErrors > | try_receive () |
Tries to receive a message without blocking. | |
Optional< T > | receive_block () |
Blocks until a message is ready. | |
template<typename Clock, typename Duration> | |
Result< Optional< T >, ChannelReceiveBeforeErrors > | receive_before (const std::chrono::time_point< Clock, Duration > &timePoint) |
Blocks until a message is ready, or erros if a timeout occurs. | |
void | deinit (Allocator &alloc) |
Deinitializes and cancels Subscription Note: This will cancel all copies of this particular Subscription. | |
void | close () |
Subscription ()=default | |
Subscription (const Arc< impl::Broker< T > > &broker, const Handle &handle) | |
Represents a pub/sub subscription which can receive messages of type T Under the hood, each publisher maintains a message broker which stores all messages Subscribers will hold an Arc to the broker and will retrieve messages from the broker Due to the broker being shared, it does require more locks for both reads and writes This means it has a pretty low throughput when there is lots of contention The primary advantage is it has a much more convenient API for more non-blocking operations or timed blocks The reason this happens is that publishers are given greater insight into each subscription, and can better avoid partial writes.
Partial sends may still happen, but they only happen if an allocating send function is used, and an allocation fails to grow the size of one of the channels.
Meant for use with select()
T | Message Type |
Definition at line 103 of file pub_sub.hpp.
using mtcore::thread::Subscription< T >::Message = T |
Definition at line 104 of file pub_sub.hpp.
|
default |
|
inline |
Definition at line 224 of file pub_sub.hpp.
|
inline |
Definition at line 220 of file pub_sub.hpp.
|
inline |
Deinitializes and cancels Subscription Note: This will cancel all copies of this particular Subscription.
Definition at line 207 of file pub_sub.hpp.
|
inline |
Blocks until a message is ready, or erros if a timeout occurs.
Definition at line 173 of file pub_sub.hpp.
|
inline |
Blocks until a message is ready.
Definition at line 142 of file pub_sub.hpp.
|
inline |
Tries to receive a message without blocking.
Definition at line 111 of file pub_sub.hpp.