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_strategy::{
event_listener::{Event, EventListener},
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.