Engine → Core → event_bus.h
event_bus
| Type | Class |
| Namespace | conjure::core |
| Include File Path | engine/include/conjure/core/event_bus.h |
| Source File Path | engine/src/core/time/event_bus.cpp |
| API ↗ | Time, events and random |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | event_bus(); |
Important
Copy constructor and assignment has been deleted. Move constructors have been deleted. Move assignment has been deleted.
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~event_bus(); |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | mChannels | std:: | {} | |
| private | mQueue | std:: | {} | |
| private | mQueueMutex | mutable std::mutex | {} |
Functions
Public
clear_queue
clear_queuevoid clear_queue();Drops every queued event without publishing it. Thread-safe.
dispatch_queued
dispatch_queuedusize dispatch_queued();Publishes every event enqueued before the call, in enqueue order, and returns how many were published (events whose type has no subscriber count too). Events enqueued while dispatching (by handlers or other threads) wait for the next call; a handler may call this re-entrantly to drain them early. Main thread only.
enqueue
enqueuetemplate <typename Event> void enqueue(
Event eventValue);Stores a copy of the event for the next dispatch_queued(). Thread-safe.
publish
publishtemplate <typename Event> void publish(
const Event &eventValue);Delivers the event to every subscriber of its type now, on the calling thread. Publishing a type nobody listens to does nothing.
queued_count
queued_count[[nodiscard]] usize queued_count() const;Number of events waiting for dispatch_queued(). Thread-safe.
subscribe
subscribetemplate <typename Event> [[nodiscard]] event_subscription subscribe(
std::function<void(const Event &)> handler);Registers a handler for one event type. The subscription follows event semantics: RAII, move-only, inert once the bus is destroyed.
subscriber_count
subscriber_counttemplate <typename Event> [[nodiscard]] usize subscriber_count() const noexcept;Number of live subscriptions for one event type.
Private
channel_for
channel_fortemplate <typename Event> [[nodiscard]] channel<Event> &channel_for();find_channel
find_channeltemplate <typename Event> [[nodiscard]] const channel<Event> *find_channel() const noexcept;