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 Notifier
s can be polled indefinitely without causing
panics or undefined behavior. They are not required to continue sending
events indefinitely, though.
Required Associated Types
Required Methods
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::Event
s with a function.