-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Description
There are a bunch of instances where it is useful to wait for the next time
that the event loop is idle and it would be nice to have first party support for
that when running in an async context.
Granted, it is pretty easy to implement that code on the user-side - I think it
should be something like this:
use std::{future::Future, pin::Pin};
use calloop::{sources::Idle, LoopHandle};
pub struct IdleFuture {
calloop: LoopHandle<'static, _>
idle: Option<Idle<'static>>,
}
impl Future for IdleFuture {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match &mut self.idle {
// On first poll set up the waker
idle @ None => {
let waker = cx.waker.clone()
let idle = self.calloop.insert_idle(move |_|{
waker.wake()
});
Poll::Pending
}
// On the second poll return to the user
idle @ Some(_) => {
idle = None;
Poll::Ready(())
}
}
}
}
But having direct support for it would be nicer!
Metadata
Metadata
Assignees
Labels
No labels