Struct simple_async_local_executor::Executor[][src]

pub struct Executor { /* fields omitted */ }

Single-threaded polling-based executor

This is a thin-wrapper (using Rc) around the real executor, so that this struct can be cloned and passed around.

See the module documentation for more details.

Implementations

impl Executor[src]

pub fn spawn(&self, future: impl Future<Output = ()> + 'static)[src]

Spawn a new task to be run by this executor.

Example

async fn nop() {}
let executor = Executor::default();
executor.spawn(nop());
assert_eq!(executor.step(), false);

pub fn create_event_handle(&self) -> EventHandle[src]

Create an event handle, that can be used to await and notify an event.

pub fn notify_event(&self, handle: &EventHandle)[src]

Notify an event.

All tasks currently waiting on this event will progress at the next call to step.

pub fn event(&self, handle: &EventHandle) -> EventFuture

Notable traits for EventFuture

impl Future for EventFuture type Output = ();
[src]

Create an event future.

Once this future is awaited, its task will be blocked until the next step after notify_event is called with this handle.

pub fn step(&self) -> bool[src]

Run each non-blocked task exactly once.

Return whether there are any non-completed tasks.

Example

let executor = Executor::default();
let event = executor.create_event_handle();
async fn wait_event(event: EventHandle, executor: Executor) {
    executor.event(&event).await;
}
executor.spawn(wait_event(event.clone(), executor.clone()));
assert_eq!(executor.step(), true); // still one task in the queue
executor.notify_event(&event);
assert_eq!(executor.step(), false); // no more task in the queue

Trait Implementations

impl Clone for Executor[src]

impl Default for Executor[src]

Auto Trait Implementations

impl !RefUnwindSafe for Executor

impl !Send for Executor

impl !Sync for Executor

impl Unpin for Executor

impl !UnwindSafe for Executor

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> 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.