diff --git a/crates/bevy_tasks/Cargo.toml b/crates/bevy_tasks/Cargo.toml index c67956fcc5fac..7759b34efe190 100644 --- a/crates/bevy_tasks/Cargo.toml +++ b/crates/bevy_tasks/Cargo.toml @@ -13,6 +13,6 @@ edition = "2018" [dependencies] futures-lite = "1.4.0" event-listener = "2.4.0" -async-executor = "1.1.1" +async-executor = "1.3.0" async-channel = "1.4.2" num_cpus = "1" diff --git a/crates/bevy_tasks/src/task_pool.rs b/crates/bevy_tasks/src/task_pool.rs index d9dda93901f3c..e8a0b559f2b61 100644 --- a/crates/bevy_tasks/src/task_pool.rs +++ b/crates/bevy_tasks/src/task_pool.rs @@ -83,7 +83,7 @@ pub struct TaskPool { /// This has to be separate from TaskPoolInner because we have to create an Arc to /// pass into the worker threads, and we must create the worker threads before we can create the /// Vec> contained within TaskPoolInner - executor: Arc, + executor: Arc>, /// Inner state of the pool inner: Arc, @@ -219,20 +219,13 @@ impl Default for TaskPool { } pub struct Scope<'scope, T> { - executor: &'scope async_executor::Executor, + executor: &'scope async_executor::Executor<'scope>, spawned: Vec>, } -impl<'scope, T: Send + 'static> Scope<'scope, T> { +impl<'scope, T: Send + 'scope> Scope<'scope, T> { pub fn spawn + 'scope + Send>(&mut self, f: Fut) { - // SAFETY: This function blocks until all futures complete, so we do not read/write the - // data from futures outside of the 'scope lifetime. However, rust has no way of knowing - // this so we must convert to 'static here to appease the compiler as it is unable to - // validate safety. - let fut: Pin + 'scope + Send>> = Box::pin(f); - let fut: Pin + 'static + Send>> = unsafe { mem::transmute(fut) }; - - let task = self.executor.spawn(fut); + let task = self.executor.spawn(f); self.spawned.push(task); } }