Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bushrat011899 committed Jan 10, 2025
1 parent b77e3ef commit ac21057
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions crates/bevy_tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ extern crate std;

extern crate alloc;

#[cfg(not(any(feature = "async_executor", feature = "edge_executor")))]
compile_error!("Either of the `async_executor` or the `edge_executor` features must be enabled.");

#[cfg(not(target_arch = "wasm32"))]
mod conditional_send {
/// Use [`ConditionalSend`] to mark an optional Send trait bound. Useful as on certain platforms (eg. Wasm),
Expand Down Expand Up @@ -45,6 +48,7 @@ pub type BoxedFuture<'a, T> = core::pin::Pin<Box<dyn ConditionalSendFuture<Outpu

pub mod futures;

#[cfg(any(feature = "async_executor", feature = "edge_executor"))]
mod executor;

mod slice;
Expand Down
42 changes: 40 additions & 2 deletions crates/bevy_tasks/src/single_threaded_task_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,50 @@ use portable_atomic_util::Arc;
#[cfg(not(feature = "portable-atomic"))]
use alloc::sync::Arc;

#[cfg(feature = "std")]
#[cfg(all(
feature = "std",
any(feature = "async_executor", feature = "edge_executor")
))]
use crate::executor::LocalExecutor;

#[cfg(not(feature = "std"))]
#[cfg(all(
not(feature = "std"),
any(feature = "async_executor", feature = "edge_executor")
))]
use crate::executor::Executor as LocalExecutor;

#[cfg(not(any(feature = "async_executor", feature = "edge_executor")))]
mod dummy_executor {
use async_task::Task;
use core::{future::Future, marker::PhantomData};

/// Dummy implementation of a `LocalExecutor` to allow for a cleaner compiler error
/// due to missing feature flags.
#[doc(hidden)]
#[derive(Debug)]
pub struct LocalExecutor<'a>(PhantomData<fn(&'a ())>);

impl<'a> LocalExecutor<'a> {
/// Dummy implementation
pub const fn new() -> Self {
Self(PhantomData)
}

/// Dummy implementation
pub fn try_tick(&self) -> bool {
unimplemented!()
}

/// Dummy implementation
pub fn spawn<T: 'a>(&self, _: impl Future<Output = T> + 'a) -> Task<T> {
unimplemented!()
}
}
}

#[cfg(not(any(feature = "async_executor", feature = "edge_executor")))]
use dummy_executor::LocalExecutor;

#[cfg(feature = "std")]
thread_local! {
static LOCAL_EXECUTOR: LocalExecutor<'static> = const { LocalExecutor::new() };
Expand Down

0 comments on commit ac21057

Please sign in to comment.