Skip to content

Commit

Permalink
fix: fix promise can't wake tokio
Browse files Browse the repository at this point in the history
  • Loading branch information
L-jasmine committed Dec 26, 2023
1 parent 05b3dbf commit 983629e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/quickjs_sys/js_promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl Context {
}
log::trace!("rt {:?} wake", waker);
waker.map(|waker| waker.wake());
tokio::task::spawn(tokio::task::yield_now());
});

self.event_loop().map(|event_loop| {
Expand All @@ -49,13 +50,16 @@ impl Future for Runtime {
cx: &mut std::task::Context<'_>,
) -> Poll<Self::Output> {
unsafe {
log::trace!("Runtime poll");

let rt = self.rt.0;
let event_loop = { (JS_GetRuntimeOpaque(rt) as *mut EventLoop).as_mut() };
if let Some(event_loop) = event_loop {
let waker = cx.waker().clone();
event_loop.waker.insert(waker);

if self.run_loop_without_io() < 0 {
log::trace!("Runtime Ready io < 0");
return Poll::Ready(());
}
loop {
Expand All @@ -65,15 +69,18 @@ impl Future for Runtime {
continue;
} else {
event_loop.sub_tasks.push_front(task);
log::trace!("Runtime Pending");
return Poll::Pending;
}
}
None => {
log::trace!("Runtime Ready sub_tasks empty");
return Poll::Ready(());
}
}
}
} else {
log::trace!("Runtime Ready sub_tasks empty");
Poll::Ready(())
}
}
Expand Down

0 comments on commit 983629e

Please sign in to comment.