1#![doc = include_str!("../README.md")]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3#![doc(
4 html_logo_url = "https://bevy.org/assets/icon.png",
5 html_favicon_url = "https://bevy.org/assets/icon.png"
6)]
7#![no_std]
8
9pub mod cfg {
11 pub(crate) use bevy_platform::cfg::*;
12
13 pub use bevy_platform::cfg::{alloc, std, web};
14
15 define_alias! {
16 #[cfg(feature = "async_executor")] => {
17 async_executor
19 }
20
21 #[cfg(all(not(target_arch = "wasm32"), feature = "multi_threaded"))] => {
22 multi_threaded
24 }
25
26 #[cfg(target_arch = "wasm32")] => {
27 conditional_send
29 }
30
31 }
32}
33
34cfg::std! {
35 extern crate std;
36}
37
38extern crate alloc;
39
40cfg::conditional_send! {
41 if {
42 pub trait ConditionalSend {}
45 impl<T> ConditionalSend for T {}
46 } else {
47 pub trait ConditionalSend: Send {}
50 impl<T: Send> ConditionalSend for T {}
51 }
52}
53
54pub trait ConditionalSendFuture: Future + ConditionalSend {}
57
58impl<T: Future + ConditionalSend> ConditionalSendFuture for T {}
59
60use alloc::boxed::Box;
61
62pub type BoxedFuture<'a, T> = core::pin::Pin<Box<dyn ConditionalSendFuture<Output = T> + 'a>>;
64
65mod executor;
67pub mod futures;
68mod iter;
69mod slice;
70mod usages;
71
72cfg::async_executor! {
73 if {} else {
74 mod edge_executor;
75 }
76}
77
78pub use async_task::Task;
80pub use iter::ParallelIterator;
81pub use slice::{ParallelSlice, ParallelSliceMut};
82pub use usages::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool};
83
84pub use futures_lite;
85pub use futures_lite::future::poll_once;
86
87cfg::web! {
88 if {} else {
89 pub use usages::tick_global_task_pools_on_main_thread;
90 }
91}
92
93cfg::multi_threaded! {
94 if {
95 mod task_pool;
96 mod thread_executor;
97
98 pub use task_pool::{Scope, TaskPool, TaskPoolBuilder};
99 pub use thread_executor::{ThreadExecutor, ThreadExecutorTicker};
100 } else {
101 mod single_threaded_task_pool;
102
103 pub use single_threaded_task_pool::{Scope, TaskPool, TaskPoolBuilder, ThreadExecutor};
104 }
105}
106
107pub use bevy_platform::future::block_on;
108
109pub mod prelude {
113 #[doc(hidden)]
114 pub use crate::{
115 block_on,
116 iter::ParallelIterator,
117 slice::{ParallelSlice, ParallelSliceMut},
118 usages::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool},
119 };
120}
121
122pub fn available_parallelism() -> usize {
129 cfg::switch! {{
130 cfg::std => {
131 std::thread::available_parallelism()
132 .map(core::num::NonZero::<usize>::get)
133 .unwrap_or(1)
134 }
135 _ => {
136 1
137 }
138 }}
139}