Skip to content

Commit 9e77393

Browse files
committed
don't move spawned array
1 parent 6c7bb03 commit 9e77393

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

crates/bevy_tasks/src/task_pool.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::{
22
future::Future,
33
marker::PhantomData,
44
mem,
5-
pin::Pin,
65
sync::Arc,
76
thread::{self, JoinHandle},
87
};
@@ -268,9 +267,9 @@ impl TaskPool {
268267
if spawned.is_empty() {
269268
Vec::new()
270269
} else {
271-
let get_results = async move {
272-
let mut results = Vec::with_capacity(spawned.len());
273-
while let Ok(task) = spawned.pop() {
270+
let get_results = async {
271+
let mut results = Vec::with_capacity(spawned_ref.len());
272+
while let Ok(task) = spawned_ref.pop() {
274273
results.push(task.await.unwrap());
275274
}
276275

@@ -280,23 +279,8 @@ impl TaskPool {
280279
// Pin the futures on the stack.
281280
pin!(get_results);
282281

283-
// SAFETY: This function blocks until all futures complete, so we do not read/write
284-
// the data from futures outside of the 'scope lifetime. However,
285-
// rust has no way of knowing this so we must convert to 'static
286-
// here to appease the compiler as it is unable to validate safety.
287-
let get_results: Pin<&mut (dyn Future<Output = Vec<T>> + 'static + Send)> = get_results;
288-
let get_results: Pin<&'static mut (dyn Future<Output = Vec<T>> + 'static + Send)> =
289-
unsafe { mem::transmute(get_results) };
290-
291-
// The thread that calls scope() will participate in driving tasks in the pool
292-
// forward until the tasks that are spawned by this scope() call
293-
// complete. (If the caller of scope() happens to be a thread in
294-
// this thread pool, and we only have one thread in the pool, then
295-
// simply calling future::block_on(spawned) would deadlock.)
296-
let mut spawned = task_scope_executor.spawn(get_results);
297-
298282
loop {
299-
if let Some(result) = future::block_on(future::poll_once(&mut spawned)) {
283+
if let Some(result) = future::block_on(future::poll_once(&mut get_results)) {
300284
break result;
301285
};
302286

0 commit comments

Comments
 (0)