mirror of
https://github.com/wez/wezterm.git
synced 2024-11-22 22:42:48 +03:00
promise: remove Executors
This commit is contained in:
parent
55e1cceb87
commit
27d58ae371
@ -13,26 +13,6 @@ pub type SpawnFunc = Box<dyn FnOnce() + Send>;
|
||||
#[error("Promise was dropped before completion")]
|
||||
pub struct BrokenPromise {}
|
||||
|
||||
pub trait BasicExecutor {
|
||||
fn execute(&self, f: SpawnFunc);
|
||||
}
|
||||
|
||||
pub trait Executor: BasicExecutor + Send {
|
||||
fn clone_executor(&self) -> Box<dyn Executor>;
|
||||
}
|
||||
|
||||
impl BasicExecutor for Box<dyn Executor> {
|
||||
fn execute(&self, f: SpawnFunc) {
|
||||
BasicExecutor::execute(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Executor for Box<dyn Executor> {
|
||||
fn clone_executor(&self) -> Box<dyn Executor> {
|
||||
Executor::clone_executor(&**self)
|
||||
}
|
||||
}
|
||||
|
||||
enum PromiseState<T> {
|
||||
Waiting(Arc<Core<T>>),
|
||||
Fulfilled,
|
||||
@ -166,26 +146,6 @@ impl<T: Send + 'static> Future<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a future from a function that will be spawned via
|
||||
/// the provided executor
|
||||
pub fn with_executor<F, IF, EXEC>(executor: EXEC, f: F) -> Future<T>
|
||||
where
|
||||
F: FnOnce() -> IF + Send + 'static,
|
||||
IF: Into<Future<T>> + 'static,
|
||||
EXEC: BasicExecutor,
|
||||
{
|
||||
let mut promise = Promise::new();
|
||||
let future = promise.get_future().unwrap();
|
||||
|
||||
let func = Box::new(f);
|
||||
let promise_chain = Box::new(move |result| promise.result(result));
|
||||
executor.execute(Box::new(move || {
|
||||
let future = func().into();
|
||||
future.chain(promise_chain);
|
||||
}));
|
||||
future
|
||||
}
|
||||
|
||||
fn chain(self, f: NextFunc<T>) {
|
||||
match self.state {
|
||||
FutureState::Ready(result) => {
|
||||
|
Loading…
Reference in New Issue
Block a user