Fix hangs in new dispatcher
Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
90facc051a
commit
6ee93125d0
11 changed files with 93 additions and 44 deletions
|
@ -88,16 +88,7 @@ impl BackgroundExecutor {
|
|||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn block_test<R>(&self, future: impl Future<Output = R>) -> R {
|
||||
let (runnable, task) = unsafe {
|
||||
async_task::spawn_unchecked(future, {
|
||||
let dispatcher = self.dispatcher.clone();
|
||||
move |runnable| dispatcher.dispatch_on_main_thread(runnable)
|
||||
})
|
||||
};
|
||||
|
||||
runnable.schedule();
|
||||
|
||||
self.block_internal(false, task)
|
||||
self.block_internal(false, future)
|
||||
}
|
||||
|
||||
pub fn block<R>(&self, future: impl Future<Output = R>) -> R {
|
||||
|
@ -109,20 +100,19 @@ impl BackgroundExecutor {
|
|||
background_only: bool,
|
||||
future: impl Future<Output = R>,
|
||||
) -> R {
|
||||
dbg!("block_internal");
|
||||
pin_mut!(future);
|
||||
let (parker, unparker) = parking::pair();
|
||||
let unparker = self.dispatcher.unparker();
|
||||
let awoken = Arc::new(AtomicBool::new(false));
|
||||
let awoken2 = awoken.clone();
|
||||
|
||||
let waker = waker_fn(move || {
|
||||
dbg!("WAKING UP.");
|
||||
awoken2.store(true, SeqCst);
|
||||
unparker.unpark();
|
||||
let waker = waker_fn({
|
||||
let awoken = awoken.clone();
|
||||
move || {
|
||||
awoken.store(true, SeqCst);
|
||||
unparker.unpark();
|
||||
}
|
||||
});
|
||||
let mut cx = std::task::Context::from_waker(&waker);
|
||||
|
||||
dbg!("BOOOP");
|
||||
loop {
|
||||
match future.as_mut().poll(&mut cx) {
|
||||
Poll::Ready(result) => return result,
|
||||
|
@ -143,9 +133,8 @@ impl BackgroundExecutor {
|
|||
panic!("parked with nothing left to run\n{:?}", backtrace_message)
|
||||
}
|
||||
}
|
||||
dbg!("PARKING!");
|
||||
parker.park();
|
||||
dbg!("CONTINUING!");
|
||||
|
||||
self.dispatcher.park();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue