Skip to content

Commit

Permalink
Update async-executor to 1.3.0 (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stjepan Glavina authored Sep 20, 2020
1 parent 924afc3 commit b05708f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_tasks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 4 additions & 11 deletions crates/bevy_tasks/src/task_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub struct TaskPool {
/// This has to be separate from TaskPoolInner because we have to create an Arc<Executor> to
/// pass into the worker threads, and we must create the worker threads before we can create the
/// Vec<Task<T>> contained within TaskPoolInner
executor: Arc<async_executor::Executor>,
executor: Arc<async_executor::Executor<'static>>,

/// Inner state of the pool
inner: Arc<TaskPoolInner>,
Expand Down Expand Up @@ -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<async_executor::Task<T>>,
}

impl<'scope, T: Send + 'static> Scope<'scope, T> {
impl<'scope, T: Send + 'scope> Scope<'scope, T> {
pub fn spawn<Fut: Future<Output = T> + '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<Box<dyn Future<Output = T> + 'scope + Send>> = Box::pin(f);
let fut: Pin<Box<dyn Future<Output = T> + 'static + Send>> = unsafe { mem::transmute(fut) };

let task = self.executor.spawn(fut);
let task = self.executor.spawn(f);
self.spawned.push(task);
}
}
Expand Down

0 comments on commit b05708f

Please sign in to comment.