mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-17 07:49:29 +00:00
Fix block to allow for sync progress
This commit is contained in:
parent
b8e007c6ec
commit
81f8e81e48
1 changed files with 13 additions and 1 deletions
|
@ -2,11 +2,15 @@ use crate::{AppContext, PlatformDispatcher};
|
||||||
use futures::{channel::mpsc, pin_mut};
|
use futures::{channel::mpsc, pin_mut};
|
||||||
use smol::prelude::*;
|
use smol::prelude::*;
|
||||||
use std::{
|
use std::{
|
||||||
|
borrow::BorrowMut,
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
mem,
|
mem,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
sync::Arc,
|
sync::{
|
||||||
|
atomic::{AtomicBool, Ordering::SeqCst},
|
||||||
|
Arc,
|
||||||
|
},
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
@ -136,7 +140,11 @@ impl Executor {
|
||||||
pub fn block<R>(&self, future: impl Future<Output = R>) -> R {
|
pub fn block<R>(&self, future: impl Future<Output = R>) -> R {
|
||||||
pin_mut!(future);
|
pin_mut!(future);
|
||||||
let (parker, unparker) = parking::pair();
|
let (parker, unparker) = parking::pair();
|
||||||
|
let awoken = Arc::new(AtomicBool::new(false));
|
||||||
|
let awoken2 = awoken.clone();
|
||||||
|
|
||||||
let waker = waker_fn(move || {
|
let waker = waker_fn(move || {
|
||||||
|
awoken2.store(true, SeqCst);
|
||||||
unparker.unpark();
|
unparker.unpark();
|
||||||
});
|
});
|
||||||
let mut cx = std::task::Context::from_waker(&waker);
|
let mut cx = std::task::Context::from_waker(&waker);
|
||||||
|
@ -146,6 +154,10 @@ impl Executor {
|
||||||
Poll::Ready(result) => return result,
|
Poll::Ready(result) => return result,
|
||||||
Poll::Pending => {
|
Poll::Pending => {
|
||||||
if !self.dispatcher.poll() {
|
if !self.dispatcher.poll() {
|
||||||
|
if awoken.swap(false, SeqCst) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
if let Some(test) = self.dispatcher.as_test() {
|
if let Some(test) = self.dispatcher.as_test() {
|
||||||
if !test.parking_allowed() {
|
if !test.parking_allowed() {
|
||||||
|
|
Loading…
Reference in a new issue