Struct calloop::LoopHandle
source · pub struct LoopHandle<'l, Data> {
inner: Rc<LoopInner<'l, Data>>,
}
Expand description
An handle to an event loop
This handle allows you to insert new sources and idles in this event loop, it can be cloned, and it is possible to insert new sources from within a source callback.
Fields§
§inner: Rc<LoopInner<'l, Data>>
Implementations§
source§impl<'l, Data> LoopHandle<'l, Data>
impl<'l, Data> LoopHandle<'l, Data>
sourcepub fn insert_source<S, F>(
&self,
source: S,
callback: F,
) -> Result<RegistrationToken, InsertError<S>>
pub fn insert_source<S, F>( &self, source: S, callback: F, ) -> Result<RegistrationToken, InsertError<S>>
Inserts a new event source in the loop.
The provided callback will be called during the dispatching cycles whenever the
associated source generates events, see EventLoop::dispatch(..)
for details.
This function takes ownership of the event source. Use register_dispatcher
if you need access to the event source after this call.
sourcepub fn register_dispatcher<S>(
&self,
dispatcher: Dispatcher<'l, S, Data>,
) -> Result<RegistrationToken>where
S: EventSource + 'l,
pub fn register_dispatcher<S>(
&self,
dispatcher: Dispatcher<'l, S, Data>,
) -> Result<RegistrationToken>where
S: EventSource + 'l,
Registers a Dispatcher
in the loop.
Use this function if you need access to the event source after its insertion in the loop.
See also insert_source
.
sourcepub fn insert_idle<'i, F: FnOnce(&mut Data) + 'l + 'i>(
&self,
callback: F,
) -> Idle<'i>
pub fn insert_idle<'i, F: FnOnce(&mut Data) + 'l + 'i>( &self, callback: F, ) -> Idle<'i>
Inserts an idle callback.
This callback will be called during a dispatching cycle when the event loop has finished processing all pending events from the sources and becomes idle.
sourcepub fn enable(&self, token: &RegistrationToken) -> Result<()>
pub fn enable(&self, token: &RegistrationToken) -> Result<()>
Enables this previously disabled event source.
This previously disabled source will start generating events again.
Note: this cannot be done from within the source callback.
sourcepub fn update(&self, token: &RegistrationToken) -> Result<()>
pub fn update(&self, token: &RegistrationToken) -> Result<()>
Makes this source update its registration.
If after accessing the source you changed its parameters in a way that requires updating its registration.
sourcepub fn disable(&self, token: &RegistrationToken) -> Result<()>
pub fn disable(&self, token: &RegistrationToken) -> Result<()>
Disables this event source.
The source remains in the event loop, but it’ll no longer generate events
sourcepub fn remove(&self, token: RegistrationToken)
pub fn remove(&self, token: RegistrationToken)
Removes this source from the event loop.
sourcepub fn adapt_io<F: AsFd>(&self, fd: F) -> Result<Async<'l, F>>
pub fn adapt_io<F: AsFd>(&self, fd: F) -> Result<Async<'l, F>>
Wrap an IO object into an async adapter
This adapter turns the IO object into an async-aware one that can be used in futures. The readiness of these futures will be driven by the event loop.
The produced futures can be polled in any executor, and notably the one provided by calloop.