pub struct EventReactor {
pub(crate) receiver: UnboundedReceiver<TorEvent>,
pub(crate) broadcast: Sender<TorEvent>,
}
Expand description
A reactor used to forward events to make the event reporting system work.
§Note
Currently, this type is a singleton; there is one event reporting system used for the entire program. This is not stable, and may change in future.
Fields§
§receiver: UnboundedReceiver<TorEvent>
A receiver that the reactor uses to learn about incoming events.
This is unbounded so that event publication doesn’t have to be async.
broadcast: Sender<TorEvent>
A sender that the reactor uses to publish events.
Events are only sent here if at least one subscriber currently wants them.
Implementations§
Source§impl EventReactor
impl EventReactor
Sourcepub fn new() -> Option<Self>
pub fn new() -> Option<Self>
Initialize the event reporting system, returning a reactor that must be run for it to work,
and a TorEventReceiver
that can be used to extract events from the system. If the system
has already been initialized, returns None
instead of a reactor.
§Warnings
The returned reactor must be run with EventReactor::run
, in a background async task.
If it is not, the event system might consume unbounded amounts of memory.
Sourcepub fn receiver() -> Option<TorEventReceiver>
pub fn receiver() -> Option<TorEventReceiver>
Get a TorEventReceiver
to receive events from, assuming an EventReactor
is already
running somewhere. (If it isn’t, returns None
.)
As noted in the type-level documentation, this function might not always work this way.