levilamina::bus¶
The cross-mod event bus: broadcast, with no return value.
Complementary to crate::service: the bus is one to many, returns nothing and guarantees no
order, while a service is one to one, returns a value and holds its name exclusively.
A mod does not receive its own publish
A mod does not receive its own publish. Notifying yourself is a direct function call, and publishing to yourself is the one cycle no depth limit can tell apart. A cross-mod cycle, A to B to A, is caught by the depth cap, and hitting it discards the innermost publish with a log line.
The whole family is thread safe and a callback runs on the publisher's thread
A callback therefore must not touch world state; touching it means Host::schedule back onto
the server thread.
Functions¶
bus::subscribe¶
| Rust | |
|---|---|
Subscribes to a topic.
A true from the callback is a veto, which only publish_vetoable reads; an
ordinary publish ignores the return value.
- Parameters:
- topic :
&str - handler :
impl FnMut(&str, &str) -> bool + Send + 'static,
- topic :
- Return type:
Result<Subscription> - Slots:
bus_subscribe
bus::publish¶
| Rust | |
|---|---|
Broadcasts. It returns how many subscribers really ran, and 0 is a normal result meaning nobody is listening.
- Parameters:
- topic :
&str - payload :
&str
- topic :
- Return type:
Result<u32> - Slots:
bus_publish
bus::publish_vetoable¶
| Rust | |
|---|---|
Broadcasts and collects the veto bit.
- Parameters:
- topic :
&str - payload :
&str
- topic :
- Return type:
Result<Vetoable> - Slots:
bus_publish_vetoable
bus::subscriber_count¶
| Rust | |
|---|---|
How many subscribers this topic currently has, across every mod.
For skipping the cost of assembling a payload nobody will read.
- Parameters:
- topic :
&str
- topic :
- Return type:
u32 - Slots:
bus_subscriber_count,bus_subscriber_count
Subscription¶
One subscription. Dropping it unsubscribes.
Subscription::forget keeps it alive until the mod unloads, when the host clears it.
- Implements:
Drop
Subscription::id¶
| Rust | |
|---|---|
- Return type:
u64
Subscription::topic¶
| Rust | |
|---|---|
- Return type:
&str
Subscription::forget¶
| Rust | |
|---|---|
Vetoable¶
| Rust | |
|---|---|
The result of one vetoable broadcast.
- Implements:
Debug,Clone,Copy,PartialEq,Eq