Struct eventador::Eventador[][src]

pub struct Eventador { /* fields omitted */ }

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]

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

impl Clone for Eventador[src]

impl From<Arc<RingBuffer>> for Eventador[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.