logo
pub trait Notifier {
    type Event;

    fn poll_next(self: Pin<&mut Self>, e: &mut Exec<'_>) -> Poll<Self::Event>;

    fn next(&mut self) -> EventFuture<'_, Self>
    where
        Self: Sized + Unpin
, { ... } fn map<B, F>(self, f: F) -> Map<Self, F>
    where
        Self: Sized + Unpin
, { ... } }
Expand description

Trait for asynchronous event notification.

Similar to AsyncIterator, but infinite.

It’s expected that Notifiers can be polled indefinitely without causing panics or undefined behavior. They are not required to continue sending events indefinitely, though.

Required Associated Types

The event produced by this notifier

Required Methods

Get the next event from this notifier, registering a wakeup when not ready.

Return Value
  • Poll::Pending - Not ready yet
  • Poll::Ready(val) - Ready with next value

Provided Methods

Get the next Self::Event

Usage
use pasts::{Notifier, prelude::*};

struct MyAsyncIter;

impl Notifier for MyAsyncIter {
    type Event = Option<u32>;

    fn poll_next(self: Pin<&mut Self>, _: &mut Exec<'_>) -> Poll<Self::Event> {
        Ready(Some(1))
    }
}

async fn run() {
    let mut count = 0;
    let mut async_iter = MyAsyncIter;
    let mut iterations = 0;
    while let Some(i) = async_iter.next().await {
        count += i;
        iterations += 1;
        if iterations == 3 {
            break;
        }
    }
    assert_eq!(count, 3);
}

pasts::Executor::default().spawn(run());

Transform produced Self::Events with a function.

Implementations on Foreign Types

Implementors