pub struct Executor { /* private fields */ }
Expand description
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§
Source§impl Executor
impl Executor
Sourcepub fn spawn(&self, future: impl Future<Output = ()> + 'static)
pub fn spawn(&self, future: impl Future<Output = ()> + 'static)
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);
Sourcepub fn create_event_handle(&self) -> EventHandle
pub fn create_event_handle(&self) -> EventHandle
Sourcepub fn notify_event(&self, handle: &EventHandle)
pub fn notify_event(&self, handle: &EventHandle)
Notify an event.
All tasks currently waiting on this event will
progress at the next call to step
.
Sourcepub fn event(&self, handle: &EventHandle) -> EventFuture ⓘ
pub fn event(&self, handle: &EventHandle) -> EventFuture ⓘ
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
.
Sourcepub fn step(&self) -> bool
pub fn step(&self) -> bool
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§
Auto Trait Implementations§
impl Freeze for Executor
impl !RefUnwindSafe for Executor
impl !Send for Executor
impl !Sync for Executor
impl Unpin for Executor
impl !UnwindSafe for Executor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more