bevy_tasks

Struct ComputeTaskPool

Source
pub struct ComputeTaskPool(/* private fields */);
Expand description

A newtype for a task pool for CPU-intensive work that must be completed to deliver the next frame

See TaskPool documentation for details on Bevy tasks. AsyncComputeTaskPool should be preferred if the work does not have to be completed before the next frame.

Implementations§

Source§

impl ComputeTaskPool

Source

pub fn get_or_init(f: impl FnOnce() -> TaskPool) -> &'static Self

Gets the global ComputeTaskPool instance, or initializes it with f.

Source

pub fn try_get() -> Option<&'static Self>

Attempts to get the global ComputeTaskPool instance, or returns None if it is not initialized.

Source

pub fn get() -> &'static Self

Gets the global ComputeTaskPool instance.

§Panics

Panics if the global instance has not been initialized yet.

Methods from Deref<Target = TaskPool>§

Source

pub fn thread_num(&self) -> usize

Available on WebAssembly or non-crate feature multi_threaded only.

Return the number of threads owned by the task pool

Source

pub fn scope<'env, F, T>(&self, f: F) -> Vec<T>
where F: for<'scope> FnOnce(&'env mut Scope<'scope, 'env, T>), T: Send + 'static,

Available on WebAssembly or non-crate feature 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

Source

pub fn scope_with_executor<'env, F, T>( &self, _tick_task_pool_executor: bool, _thread_executor: Option<&ThreadExecutor<'_>>, f: F, ) -> Vec<T>
where F: for<'scope> FnOnce(&'env mut Scope<'scope, 'env, T>), T: Send + 'static,

Available on WebAssembly or non-crate feature 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

Source

pub fn spawn<T>(&self, future: impl Future<Output = T> + 'static) -> Task<T>
where T: 'static,

Available on WebAssembly or non-crate feature multi_threaded only.

Spawns a static future onto the thread pool. The returned Task is a future, which can be polled to retrieve the output of the original future. Dropping the task will attempt to cancel it. It can also be “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.

Source

pub fn spawn_local<T>( &self, future: impl Future<Output = T> + 'static, ) -> Task<T>
where T: 'static,

Available on WebAssembly or non-crate feature multi_threaded only.

Spawns a static future on the JS event loop. This is exactly the same as TaskPool::spawn.

Source

pub fn with_local_executor<F, R>(&self, f: F) -> R
where F: FnOnce(&LocalExecutor<'_>) -> R,

Available on WebAssembly or non-crate feature 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();
});

Trait Implementations§

Source§

impl Debug for ComputeTaskPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for ComputeTaskPool

Source§

type Target = TaskPool

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
Available on non-bootstrap only.
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.