cab
cab4w ago

driving async ops in deno_core

What's the correct way to run a single tick of the event loop in deno_core? I'm using poll_event_loop, but the result is always pending (i.e. the timers created with core.queueUserTimer are never resolving). Is there something else I need to poll? If I use tokio.block_on(run_event_loop) it works correctly, but I only want to run a single tick. My code currently looks like this:
let mut cx = std::task::Context::from_waker(futures::task::noop_waker_ref());
let res = runtime
.js
.poll_event_loop(&mut cx, PollEventLoopOptions::default());
let mut cx = std::task::Context::from_waker(futures::task::noop_waker_ref());
let res = runtime
.js
.poll_event_loop(&mut cx, PollEventLoopOptions::default());
Thanks!
2 Replies
Deno AI Helper
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet you've provided, there doesn't seem to be any obvious syntax errors or mistakes. Please note that my advice is not based on the Deno documentation, and I recommend double-checking the accuracy of the advice given. In the context of deno_core, it's important to ensure that the event loop is being managed correctly. If poll_event_loop is always returning Pending, it might be indicative of the event loop not being driven to completion, or that the futures within the event loop are not being polled correctly. Since you're looking to run a single tick of the event loop, you might need to ensure that the runtime is set up correctly and that any necessary setup for timers or other async operations is in place before calling poll_event_loop. It's also possible that additional configuration or steps are required to properly drive the event loop for a single tick, which might not be covered in the documentation. If you continue to experience issues, I would suggest reaching out to the Deno community or looking into the source code of deno_core for more insights on how to properly drive the event loop for a single tick.
cab
cab4w ago
fixed it by yielding to tokio
block_on(async {
tokio::task::yield_now().await;
poll_once(poll_fn(|cx| {
js.poll_event_loop(cx, PollEventLoopOptions::default())
}))
.await;
});
block_on(async {
tokio::task::yield_now().await;
poll_once(poll_fn(|cx| {
js.poll_event_loop(cx, PollEventLoopOptions::default())
}))
.await;
});