Struct bevy_internal::tasks::prelude::AsyncComputeTaskPool
source · 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 AsyncComputeTaskPool
pub fn get_or_init( f: impl FnOnce() -> TaskPool ) -> &'static AsyncComputeTaskPool
Gets the global AsyncComputeTaskPool
instance, or initializes it with f
.
sourcepub fn try_get() -> Option<&'static AsyncComputeTaskPool>
pub fn try_get() -> Option<&'static AsyncComputeTaskPool>
Attempts to get the global AsyncComputeTaskPool
instance, or returns None
if it is not initialized.
sourcepub fn get() -> &'static AsyncComputeTaskPool
pub fn get() -> &'static AsyncComputeTaskPool
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
pub fn thread_num(&self) -> usize
Return the number of threads owned by the task pool
sourcepub fn scope<'env, F, T>(&self, f: F) -> Vec<T>
pub fn scope<'env, F, T>(&self, f: F) -> Vec<T>
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>
pub fn scope_with_executor<'env, F, T>( &self, _tick_task_pool_executor: bool, _thread_executor: Option<&ThreadExecutor<'_>>, f: F ) -> Vec<T>
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,
pub fn spawn<T>(&self, future: impl Future<Output = T> + 'static) -> FakeTaskwhere
T: 'static,
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,
pub fn spawn_local<T>(
&self,
future: impl Future<Output = T> + 'static
) -> FakeTaskwhere
T: 'static,
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,
pub fn with_local_executor<F, R>(&self, f: F) -> Rwhere
F: FnOnce(&LocalExecutor<'_>) -> R,
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 AsyncComputeTaskPool
impl Debug for AsyncComputeTaskPool
Auto Trait Implementations§
impl Freeze for AsyncComputeTaskPool
impl RefUnwindSafe for AsyncComputeTaskPool
impl Send for AsyncComputeTaskPool
impl Sync for AsyncComputeTaskPool
impl Unpin for AsyncComputeTaskPool
impl UnwindSafe for AsyncComputeTaskPool
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.