Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update async-executor to 1.3.0 (urgent) #526

Merged
merged 1 commit into from Sep 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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