Struct eventador::Eventador [−][src]
A lock-free and thread-safe event-bus implementation.
Example
Basic usage:
let eventbus = Eventador::new(4)?; let subscriber = eventbus.subscribe::<usize>(); let mut i: usize = 1234; eventbus.publish(i); let mut msg = subscriber.recv(); assert_eq!(i, *msg);
Implementations
impl Eventador
[src]
pub fn new(capacity: u64) -> Result<Self>
[src]
Creates a new Eventador event-bus.
The capacity is required to be a power of 2.
This uses the default wait-strategy of WaitStrategy::AllSubscribers
, which will ensure
a publisher can't overwrite an event in the ring until all subscribers have read it.
Example
Basic usage:
let eventbus = Eventador::new(4)?;
pub fn with_strategy(capacity: u64, wait_strategy: WaitStrategy) -> Result<Self>
[src]
Creates a new Eventador event-bus with a specific WaitStrategy
for publishers.
The capacity is required to be a power of 2.
Example
Basic usage:
let eventbus = Eventador::new(4, WaitStrategy::AllSubscribers)?;
pub fn publish<T: 'static + Send + Sync>(&self, message: T)
[src]
Synchronously publish an event to the event-bus.
Example
Basic usage:
let eventbus = Eventador::new(4)?; let i: usize = 1234; eventbus.publish(i);
pub fn publisher(&self) -> Publisher
[src]
Creates a Publisher
that synchronously publishes messages on the event-bus.
Although the Eventador::publish
function has the exact same behavior, this handle offers
an API that mirrors the AsyncPublisher
.
Example
Basic usage:
let eventbus = Eventador::new(4)?; let mut publisher = eventbus.publisher(); let i: usize = 1234; publisher.send(i);
pub fn subscribe<T: 'static + Send>(&self) -> Subscriber<T>
[src]
Creates a Subscriber
that subscribes to an event type receives them synchronously.
The Subscriber
will not receive subscribed events that were published to the event-bus
before time of subscription. It will only receive events that are published after
time of subscription.
Example
Basic usage:
let eventbus = Eventador::new(4)?; // subscribe first, before publishing! let subscriber = eventbus.subscribe::<usize>(); let mut i: usize = 1234; eventbus.publish(i); let mut msg = subscriber.recv(); assert_eq!(i, *msg);
pub fn async_publisher<T: 'static + Send + Sync + Unpin>(
&self,
buffer_size: usize
) -> AsyncPublisher<T>
[src]
&self,
buffer_size: usize
) -> AsyncPublisher<T>
Creates an AsyncPublisher
that can publish to the event-bus asynchronously.
The buffer size indicates the number of events that can be buffered until a flush is made to the event bus. Until events are flushed to the event bus, they are not yet published.
Because events are buffered, an AsyncPublisher can only publish events of the same type. A new AsyncPublisher must be instantiated for events of another type.
Example
Basic usage:
let eventbus = Eventador::new(4)?; let mut publisher: AsyncPublisher<usize> = eventbus.async_publisher(10); let mut i: usize = 1234; publisher.send(i).await?;
pub fn async_subscriber<T: Send + Unpin>(&self) -> AsyncSubscriber<'_, T>
[src]
Creates an AsyncSubscriber
that subscribes to an event type and receive them
asynchronously.
Example
Basic usage:
let eventbus = Eventador::new(4)?; let subscriber = eventbus.async_subscriber::<usize>(); let mut publisher: AsyncPublisher<usize> = eventbus.async_publisher(); let mut i: usize = 1234; publisher.send(i).await?; let mut msg = subscriber.next().await.unwrap(); assert_eq!(i, *msg);
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Eventador
[src]
impl Send for Eventador
[src]
impl Sync for Eventador
[src]
impl Unpin for Eventador
[src]
impl !UnwindSafe for Eventador
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,