pub struct EventLoop<'l, Data> { /* private fields */ }
Expand description
An event loop
This loop can host several event sources, that can be dynamically added or removed.
Implementations§
source§impl<'l, Data> EventLoop<'l, Data>
impl<'l, Data> EventLoop<'l, Data>
sourcepub fn try_new() -> Result<Self>
pub fn try_new() -> Result<Self>
Create a new event loop
Fails if the initialization of the polling system failed.
sourcepub fn try_new_high_precision() -> Result<Self>
pub fn try_new_high_precision() -> Result<Self>
Create a new event loop in high precision mode
On some platforms it requires to setup more resources to enable high-precision (sub millisecond) capabilities, so you should use this constructor if you need this kind of precision.
Fails if the initialization of the polling system failed.
sourcepub fn handle(&self) -> LoopHandle<'l, Data>
pub fn handle(&self) -> LoopHandle<'l, Data>
Retrieve a loop handle
sourcepub fn dispatch<D: Into<Option<Duration>>>(
&mut self,
timeout: D,
data: &mut Data
) -> Result<()>
pub fn dispatch<D: Into<Option<Duration>>>( &mut self, timeout: D, data: &mut Data ) -> Result<()>
Dispatch pending events to their callbacks
If some sources have events available, their callbacks will be immediatly called.
Otherwise this will wait until an event is receive or the provided timeout
is reached. If timeout
is None
, it will wait without a duration limit.
Once pending events have been processed or the timeout is reached, all pending idle callbacks will be fired before this method returns.
sourcepub fn get_signal(&self) -> LoopSignal
pub fn get_signal(&self) -> LoopSignal
Get a signal to stop this event loop from running
To be used in conjunction with the run()
method.
sourcepub fn run<F, D: Into<Option<Duration>>>(
&mut self,
timeout: D,
data: &mut Data,
cb: F
) -> Result<()>where
F: FnMut(&mut Data),
pub fn run<F, D: Into<Option<Duration>>>( &mut self, timeout: D, data: &mut Data, cb: F ) -> Result<()>where F: FnMut(&mut Data),
Run this event loop
This will repeatedly try to dispatch events (see the dispatch()
method) on
this event loop, waiting at most timeout
every time.
Between each dispatch wait, your provided callback will be called.
You can use the get_signal()
method to retrieve a way to stop or wakeup
the event loop from anywhere.