pub struct Context<'sel, 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
Implementations§
Source§impl<'sel, E: 'static, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> Context<'sel, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
impl<'sel, E: 'static, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> Context<'sel, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
Sourcepub fn dispatch(&self, event: E) -> Result<(), E>
pub fn dispatch(&self, event: E) -> Result<(), E>
Pushes given event into the queue that EventLoop::events
pops from.
§Errors
Returns event back if the queue already holds EVENTS events.
Sourcepub fn spawn<F, Fut>(
&self,
f: F,
) -> Result<impl Future<Output = ()> + use<E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS, F, Fut>, NotEnoughResources>
pub fn spawn<F, Fut>( &self, f: F, ) -> Result<impl Future<Output = ()> + use<E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS, F, Fut>, NotEnoughResources>
Spawns a task with a given async closure.
The future must fit TASK_SIZE bytes and be aligned to at most 16 bytes, otherwise the
program doesn’t compile.
Returns a join handle, a future that resolves once the task is finished. Dropping it detaches the task, which keeps running until it finishes.
§Errors
Returns an error if all TASKS task slots are taken, the future returned by f is dropped
without being polled then. Use reserve_task to wait for a free
slot instead.
Sourcepub fn reserve_task(
&self,
) -> impl Future<Output = Result<TaskReservation<'sel, TASKS, TASK_SIZE, ROOT_TASK_SIZE>, SlotWaiterTakenError>> + use<'sel, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
pub fn reserve_task( &self, ) -> impl Future<Output = Result<TaskReservation<'sel, TASKS, TASK_SIZE, ROOT_TASK_SIZE>, SlotWaiterTakenError>> + use<'sel, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
Reserves a task slot.
This method returns a future that is resolved once a slot in the internal pool of tasks is available.
The future stays pending until some other task finishes and frees a slot.
§Errors
Only one task can wait for a free slot at a time. The future resolves to
SlotWaiterTakenError if all TASKS slots are taken and another task already waits.
§Cancel safety
This method is cancel safe.
Sourcepub fn sleep(
&self,
duration: Duration,
) -> impl Future<Output = Result<(), NotEnoughResources>> + use<'sel, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
pub fn sleep( &self, duration: Duration, ) -> impl Future<Output = Result<(), NotEnoughResources>> + use<'sel, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
Sourcepub fn timeout<F: Future>(
&self,
duration: Duration,
future: F,
) -> impl Future<Output = Result<MaybeTimedOut<F::Output>, NotEnoughResources>>
pub fn timeout<F: Future>( &self, duration: Duration, future: F, ) -> impl Future<Output = Result<MaybeTimedOut<F::Output>, NotEnoughResources>>
Sourcepub fn notified(
&self,
) -> impl Future<Output = ()> + use<'sel, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
pub fn notified( &self, ) -> impl Future<Output = ()> + use<'sel, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
Waits until EventLoop::notify is called.
Notifications don’t queue up: any number of notify() calls made before the future is
polled resolve it only once.
Only one task can wait for a notification at a time.
§Cancel safety
This method is cancel safe.