Trait event_listener_strategy::Strategy
source · pub trait Strategy<'a> {
type Context: ?Sized;
type Future: Future + 'a;
// Required methods
fn poll<T, L: Listener<T> + Unpin>(
&mut self,
event_listener: &mut Option<L>,
context: &mut Self::Context
) -> Poll<T>;
fn wait(&mut self, evl: EventListener) -> Self::Future;
}
Expand description
A strategy for polling an EventListenerFuture
or an EventListener
.
This trait is used by the EventListenerFuture::poll_with_strategy
method to determine
how to poll the future. It can also be used standalone, by calling the Strategy::wait
method.
Examples
use event_listener::{Event, EventListener};
use event_listener_strategy::{EventListenerFuture, Strategy, Blocking, NonBlocking};
use std::pin::Pin;
async fn wait_on<'a, S: Strategy<'a>>(evl: EventListener, strategy: &mut S) {
strategy.wait(evl).await;
}
// Block on the future.
let ev = Event::new();
let listener = ev.listen();
ev.notify(1);
wait_on(listener, &mut Blocking::default()).await;
// Poll the future.
let listener = ev.listen();
ev.notify(1);
wait_on(listener, &mut NonBlocking::default()).await;
Required Associated Types§
sourcetype Future: Future + 'a
type Future: Future + 'a
The future returned by the Strategy::wait
method.
Required Methods§
sourcefn poll<T, L: Listener<T> + Unpin>(
&mut self,
event_listener: &mut Option<L>,
context: &mut Self::Context
) -> Poll<T>
fn poll<T, L: Listener<T> + Unpin>( &mut self, event_listener: &mut Option<L>, context: &mut Self::Context ) -> Poll<T>
Poll the event listener until it is ready.
sourcefn wait(&mut self, evl: EventListener) -> Self::Future
fn wait(&mut self, evl: EventListener) -> Self::Future
Wait for the event listener to become ready.
Object Safety§
This trait is not object safe.