mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
Checkpoint
This commit is contained in:
parent
72435af170
commit
e7c04d4aca
@ -1,5 +1,5 @@
|
|||||||
use crate::{AppContext, PlatformDispatcher};
|
use crate::{AppContext, PlatformDispatcher};
|
||||||
use futures::channel::mpsc;
|
use futures::{channel::mpsc, pin_mut};
|
||||||
use smol::prelude::*;
|
use smol::prelude::*;
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
@ -11,6 +11,7 @@ use std::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use util::TryFutureExt;
|
use util::TryFutureExt;
|
||||||
|
use waker_fn::waker_fn;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Executor {
|
pub struct Executor {
|
||||||
@ -133,8 +134,22 @@ impl Executor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn block<R>(&self, future: impl Future<Output = R>) -> R {
|
pub fn block<R>(&self, future: impl Future<Output = R>) -> R {
|
||||||
// todo!("integrate with deterministic dispatcher")
|
pin_mut!(future);
|
||||||
futures::executor::block_on(future)
|
let (parker, unparker) = parking::pair();
|
||||||
|
let waker = waker_fn(move || {
|
||||||
|
unparker.unpark();
|
||||||
|
});
|
||||||
|
let mut cx = std::task::Context::from_waker(&waker);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match future.as_mut().poll(&mut cx) {
|
||||||
|
Poll::Ready(result) => return result,
|
||||||
|
Poll::Pending => {
|
||||||
|
// todo!("call tick on test dispatcher")
|
||||||
|
parker.park();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn scoped<'scope, F>(&self, scheduler: F)
|
pub async fn scoped<'scope, F>(&self, scheduler: F)
|
||||||
|
Loading…
Reference in New Issue
Block a user