-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hook to be called when new pending task is available #44
Comments
If you wait on // Create a waker that wakes up the Ocaml loop when it's ready.
fn wake_up_the_ocaml_loop() { /* ... */ }
let my_waker = waker_fn::waker_fn(|| wake_up_the_ocaml_loop());
// Block on the run() future using the Ocaml loop.
let tick = executor.run(futures_lite::future::pending::<()>());
futures_lite::pin!(tick);
loop {
// Poll the tick future.
tick.poll(&mut Context::new(&my_waker));
// Block on the Ocaml loop until it's awake.
block_on_ocaml_loop();
} |
OCaml event loop is the main application that is being executed, Rust executor is auxilary and I want to notify OCaml event loop when there are runnable tasks on the Rust executor, so that OCaml side calls I've ended up with forking It can be found here in |
It seems to me from a brief glance that this is just a poor man's |
Sorry, I do not quite follow this part. With mainline Can you please expand how I can do this with an additional waker and vanilla |
I'm also running into this issue when trying to tie the executor into egui's event loop. I have the following function which is run on each iteration of the event loop: fn tick(&self) {
loop {
let tick = self.executor.tick();
futures_lite::pin!(tick);
let poll_result = tick.poll(&mut Context::from_waker(&self.waker));
if let Poll::Pending = poll_result {
// No tasks are scheduled. Exit the task loop.
break;
}
}
}
However, if I spawn a new task onto the executor after all the other tasks have been run, it seems like that task won't be called until the above Do I also need to wrap It's starting to feel less like I'm hooking up the executor to an external event loop and more like I'm writing my own half-baked executor on top of yours. My mental model--correct me if I'm wrong--is that you run futures by giving them to an executor to schedule. A future needs to be executed using an executor. So when we call |
You probably want something like this: struct EguiExecutorBridge(Box<Pin<dyn Future<Output = ()> + Send + 'static>>);
impl EguiExecutorBridge {
// Replace with Arc<Executor<'static>>, or however you're storing the executor
fn new(ex: &'static Executor<'static>) -> Self {
Self(Box::pin(async move {
ex.run(futures_lite::future::pending::<()>()).await;
})
}
fn tick(&mut self) {
// Poll with your egui waker.
let waker = waker_fn::waker_fn(|| wake_up_my_egui_loop());
let mut context = Context::new(&waker);
let _ self.0.as_mut().poll(&mut cx);
}
} This way, it sets up a local queue and keeps it running. Then, you keep the future around and poll it using the
Yes, you need to call
The task being pushed should call the waker and wake up the event loop.
Not necessarily. Futures can be blocked on anywhere with |
Closing as I feel that this question has been sufficiently answered. |
I'm integrating LocalExecutor into OCaml single-threaded event loop, so far it works great, but what I'm missing is the ability for me to register some non-async thread-safe function that will notify OCaml single-threaded event loop (via a pipe) that it needs to call
LocalExecutor::try_tick
, I have to resort to callingLocalExecutor::try_tick
"often enough", but that's obviously a suboptimal solution...Maybe there is something in the API that already allows me to do this without busy-polling?
The text was updated successfully, but these errors were encountered: