pub struct AsyncComputeTaskPool(/* private fields */);
Expand description
A newtype for a task pool for CPU-intensive work that may span across multiple frames
See TaskPool
documentation for details on Bevy tasks.
Use ComputeTaskPool
if the work must be complete before advancing to the next frame.
Implementations§
Source§impl AsyncComputeTaskPool
impl AsyncComputeTaskPool
Sourcepub fn get_or_init(f: impl FnOnce() -> TaskPool) -> &'static Self
pub fn get_or_init(f: impl FnOnce() -> TaskPool) -> &'static Self
Gets the global AsyncComputeTaskPool
instance, or initializes it with f
.
Sourcepub fn try_get() -> Option<&'static Self>
pub fn try_get() -> Option<&'static Self>
Attempts to get the global AsyncComputeTaskPool
instance, or returns None
if it is not initialized.
Sourcepub fn get() -> &'static Self
pub fn get() -> &'static Self
Gets the global AsyncComputeTaskPool
instance.
§Panics
Panics if the global instance has not been initialized yet.
Methods from Deref<Target = TaskPool>§
Sourcepub fn thread_num(&self) -> usize
Available on WebAssembly or non-crate feature multi_threaded
only.
pub fn thread_num(&self) -> usize
multi_threaded
only.Return the number of threads owned by the task pool
Sourcepub fn scope<'env, F, T>(&self, f: F) -> Vec<T>
Available on WebAssembly or non-crate feature multi_threaded
only.
pub fn scope<'env, F, T>(&self, f: F) -> Vec<T>
multi_threaded
only.Allows spawning non-'static
futures on the thread pool. The function takes a callback,
passing a scope object into it. The scope object provided to the callback can be used
to spawn tasks. This function will await the completion of all tasks before returning.
This is similar to rayon::scope
and crossbeam::scope
Sourcepub fn scope_with_executor<'env, F, T>(
&self,
_tick_task_pool_executor: bool,
_thread_executor: Option<&ThreadExecutor<'_>>,
f: F,
) -> Vec<T>
Available on WebAssembly or non-crate feature multi_threaded
only.
pub fn scope_with_executor<'env, F, T>( &self, _tick_task_pool_executor: bool, _thread_executor: Option<&ThreadExecutor<'_>>, f: F, ) -> Vec<T>
multi_threaded
only.Allows spawning non-'static
futures on the thread pool. The function takes a callback,
passing a scope object into it. The scope object provided to the callback can be used
to spawn tasks. This function will await the completion of all tasks before returning.
This is similar to rayon::scope
and crossbeam::scope
Sourcepub fn spawn<T>(&self, future: impl Future<Output = T> + 'static) -> FakeTaskwhere
T: 'static,
Available on WebAssembly or non-crate feature multi_threaded
only.
pub fn spawn<T>(&self, future: impl Future<Output = T> + 'static) -> FakeTaskwhere
T: 'static,
multi_threaded
only.Spawns a static future onto the thread pool. The returned Task is a future. It can also be cancelled and “detached” allowing it to continue running without having to be polled by the end-user.
If the provided future is non-Send
, TaskPool::spawn_local
should be used instead.
Sourcepub fn spawn_local<T>(
&self,
future: impl Future<Output = T> + 'static,
) -> FakeTaskwhere
T: 'static,
Available on WebAssembly or non-crate feature multi_threaded
only.
pub fn spawn_local<T>(
&self,
future: impl Future<Output = T> + 'static,
) -> FakeTaskwhere
T: 'static,
multi_threaded
only.Spawns a static future on the JS event loop. This is exactly the same as TaskPool::spawn
.
Sourcepub fn with_local_executor<F, R>(&self, f: F) -> Rwhere
F: FnOnce(&LocalExecutor<'_>) -> R,
Available on WebAssembly or non-crate feature multi_threaded
only.
pub fn with_local_executor<F, R>(&self, f: F) -> Rwhere
F: FnOnce(&LocalExecutor<'_>) -> R,
multi_threaded
only.Runs a function with the local executor. Typically used to tick the local executor on the main thread as it needs to share time with other things.
use bevy_tasks::TaskPool;
TaskPool::new().with_local_executor(|local_executor| {
local_executor.try_tick();
});