pub struct EventLoop<'a, E: 'static, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> { /* private fields */ }Expand description
The main type, an event loop.
Implementations§
Source§impl<'a, E: 'static, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> EventLoop<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
impl<'a, E: 'static, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> EventLoop<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
Sourcepub fn new<F, Fut>(
storage: &'static LoopStorage<E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>,
selector: &'a mut Selector,
f: F,
) -> Result<Self, EventLoopError>
pub fn new<F, Fut>( storage: &'static LoopStorage<E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>, selector: &'a mut Selector, f: F, ) -> Result<Self, EventLoopError>
Creates an event loop and polls given future once.
The future must fit ROOT_TASK_SIZE bytes and be aligned to at most 16 bytes, otherwise
the program doesn’t compile.
§Errors
Returns an error if:
storagehas already been used by another event loop,fisn’t called then- epoll/kqueue returned an error during initial poll
- given future completed during initial poll.
Sourcepub fn drain_events_without_blocking(&mut self) -> Result<(), EventLoopError>
pub fn drain_events_without_blocking(&mut self) -> Result<(), EventLoopError>
Drains all events from the underlying epollfd or kqueuefd,
polls woken futures until none is ready,
submits them back to epoll/kqueue.
§Errors
Returns an error if:
- epoll/kqueue returned an error
- root future completed
Sourcepub fn notify(&self) -> Result<()>
pub fn notify(&self) -> Result<()>
Makes the event loop’s file descriptor readable and wakes up a task
that waits on Context::notified
once you call drain_events_without_blocking.
This is the way to pass data from the external world into the event loop: store the data somewhere the task can reach it, then call this method.
§Errors
Returns an error if a syscall fails.
Sourcepub fn events(&self) -> impl Iterator<Item = E>
pub fn events(&self) -> impl Iterator<Item = E>
Returns an iterator that pops events pushed by Context::dispatch.
This is the way to pass data from the event loop to the external world.