Fix Compositor concurrent initialization
It seems that initializing the compositor in a different thread can cause issues in some environments.
This commit is contained in:
parent
d203392c9d
commit
1b22d7d5fc
8 changed files with 37 additions and 14 deletions
|
|
@ -12,6 +12,10 @@ impl crate::Executor for Executor {
|
|||
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
|
||||
smol::spawn(future).detach();
|
||||
}
|
||||
|
||||
fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
|
||||
smol::block_on(future)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod time {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ impl crate::Executor for Executor {
|
|||
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
|
||||
self.spawn_ok(future);
|
||||
}
|
||||
|
||||
fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
|
||||
futures::executor::block_on(future)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod time {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ impl crate::Executor for Executor {
|
|||
let _guard = tokio::runtime::Runtime::enter(self);
|
||||
f()
|
||||
}
|
||||
|
||||
fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
|
||||
self.block_on(future)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod time {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ impl crate::Executor for Executor {
|
|||
}
|
||||
|
||||
fn spawn(&self, _future: impl Future<Output = ()> + MaybeSend + 'static) {}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn block_on<T>(&self, _future: impl Future<Output = T>) -> T {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod time {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ pub trait Executor: Sized {
|
|||
/// Spawns a future in the [`Executor`].
|
||||
fn spawn(&self, future: impl Future<Output = ()> + MaybeSend + 'static);
|
||||
|
||||
/// Runs a future to completion in the current thread within the [`Executor`].
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn block_on<T>(&self, future: impl Future<Output = T>) -> T;
|
||||
|
||||
/// Runs the given closure inside the [`Executor`].
|
||||
///
|
||||
/// Some executors, like `tokio`, require some global state to be in place
|
||||
|
|
|
|||
|
|
@ -50,12 +50,10 @@ where
|
|||
self.executor.enter(f)
|
||||
}
|
||||
|
||||
/// Spawns a [`Future`] in the [`Runtime`].
|
||||
pub fn spawn(
|
||||
&mut self,
|
||||
future: impl Future<Output = ()> + MaybeSend + 'static,
|
||||
) {
|
||||
self.executor.spawn(future);
|
||||
/// Runs a future to completion in the current thread within the [`Runtime`].
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn block_on<T>(&mut self, future: impl Future<Output = T>) -> T {
|
||||
self.executor.block_on(future)
|
||||
}
|
||||
|
||||
/// Runs a [`Stream`] in the [`Runtime`] until completion.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue