diff --git a/src/native/mod.rs b/src/native/mod.rs index 28750e1..2475ed5 100644 --- a/src/native/mod.rs +++ b/src/native/mod.rs @@ -23,10 +23,7 @@ where } /// Add a timeout to the task. - pub fn with_timeout( - mut self, - dur: Duration, - ) -> AsyncTask> { + pub fn with_timeout(mut self, dur: Duration) -> AsyncTask> { let (tx, rx) = oneshot::channel(); let new_fut = async move { let result = timeout(dur, self.fut) @@ -64,10 +61,7 @@ impl AsyncTask { } /// Create an async task from a future with a timeout. - pub fn new_with_timeout( - dur: Duration, - fut: F, - ) -> AsyncTask> + pub fn new_with_timeout(dur: Duration, fut: F) -> AsyncTask> where F: Future + Send + 'static, F::Output: Send + 'static, @@ -213,8 +207,7 @@ mod test { #[tokio::test] async fn test_with_timeout() { - let task = - AsyncTask::<()>::pending().with_timeout(Duration::from_millis(5)); + let task = AsyncTask::<()>::pending().with_timeout(Duration::from_millis(5)); let (fut, mut rx) = task.into_parts(); assert_eq!(None, rx.try_recv()); diff --git a/src/task_pool.rs b/src/task_pool.rs index a77cfc1..6295f34 100644 --- a/src/task_pool.rs +++ b/src/task_pool.rs @@ -2,9 +2,7 @@ use crate::{AsyncReceiver, AsyncTask, AsyncTaskStatus}; use bevy::{ ecs::{ component::Tick, - system::{ - ExclusiveSystemParam, ReadOnlySystemParam, SystemMeta, SystemParam, - }, + system::{ExclusiveSystemParam, ReadOnlySystemParam, SystemMeta, SystemParam}, world::unsafe_world_cell::UnsafeWorldCell, }, prelude::*, @@ -14,9 +12,7 @@ use bevy::{ /// A Bevy [`SystemParam`] to execute many similar [`AsyncTask`]s in the /// background simultaneously. -pub struct AsyncTaskPool<'s, T>( - pub(crate) &'s mut Vec>>, -); +pub struct AsyncTaskPool<'s, T>(pub(crate) &'s mut Vec>>); impl<'s, T> AsyncTaskPool<'s, T> { /// Returns whether the task pool is idle. @@ -66,29 +62,20 @@ impl<'_s, T: Send + 'static> ExclusiveSystemParam for AsyncTaskPool<'_s, T> { } #[inline] - fn get_param<'s>( - state: &'s mut Self::State, - _system_meta: &SystemMeta, - ) -> Self::Item<'s> { + fn get_param<'s>(state: &'s mut Self::State, _system_meta: &SystemMeta) -> Self::Item<'s> { AsyncTaskPool(state.get()) } } // SAFETY: only local state is accessed -unsafe impl<'s, T: Send + 'static> ReadOnlySystemParam - for AsyncTaskPool<'s, T> -{ -} +unsafe impl<'s, T: Send + 'static> ReadOnlySystemParam for AsyncTaskPool<'s, T> {} // SAFETY: only local state is accessed unsafe impl<'a, T: Send + 'static> SystemParam for AsyncTaskPool<'a, T> { type State = SyncCell>>>; type Item<'w, 's> = AsyncTaskPool<'s, T>; - fn init_state( - _world: &mut World, - _system_meta: &mut SystemMeta, - ) -> Self::State { + fn init_state(_world: &mut World, _system_meta: &mut SystemMeta) -> Self::State { SyncCell::new(vec![]) } diff --git a/src/task_runner.rs b/src/task_runner.rs index 284ea82..3c23b82 100644 --- a/src/task_runner.rs +++ b/src/task_runner.rs @@ -2,9 +2,7 @@ use crate::{AsyncReceiver, AsyncTask, AsyncTaskStatus}; use bevy::{ ecs::{ component::Tick, - system::{ - ExclusiveSystemParam, ReadOnlySystemParam, SystemMeta, SystemParam, - }, + system::{ExclusiveSystemParam, ReadOnlySystemParam, SystemMeta, SystemParam}, world::unsafe_world_cell::UnsafeWorldCell, }, prelude::*, @@ -88,29 +86,20 @@ impl<'_s, T: Send + 'static> ExclusiveSystemParam for AsyncTaskRunner<'_s, T> { SyncCell::new(None) } - fn get_param<'s>( - state: &'s mut Self::State, - _system_meta: &SystemMeta, - ) -> Self::Item<'s> { + fn get_param<'s>(state: &'s mut Self::State, _system_meta: &SystemMeta) -> Self::Item<'s> { AsyncTaskRunner(state.get()) } } // SAFETY: only local state is accessed -unsafe impl<'s, T: Send + 'static> ReadOnlySystemParam - for AsyncTaskRunner<'s, T> -{ -} +unsafe impl<'s, T: Send + 'static> ReadOnlySystemParam for AsyncTaskRunner<'s, T> {} // SAFETY: only local state is accessed unsafe impl<'a, T: Send + 'static> SystemParam for AsyncTaskRunner<'a, T> { type State = SyncCell>>; type Item<'w, 's> = AsyncTaskRunner<'s, T>; - fn init_state( - _world: &mut World, - _system_meta: &mut SystemMeta, - ) -> Self::State { + fn init_state(_world: &mut World, _system_meta: &mut SystemMeta) -> Self::State { SyncCell::new(None) } diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 08e1b9c..2fab098 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -17,10 +17,7 @@ where T: 'static, { /// Add a timeout to the task. - pub fn with_timeout( - mut self, - dur: Duration, - ) -> AsyncTask> { + pub fn with_timeout(mut self, dur: Duration) -> AsyncTask> { let (tx, rx) = oneshot::channel(); let new_fut = async move { let result = timeout(dur, self.fut) @@ -68,10 +65,7 @@ impl AsyncTask { } /// Create an async task from a future with a timeout. - pub fn new_with_timeout( - dur: Duration, - fut: F, - ) -> AsyncTask> + pub fn new_with_timeout(dur: Duration, fut: F) -> AsyncTask> where F: Future + 'static, F::Output: Send + 'static, @@ -199,8 +193,7 @@ mod test { #[wasm_bindgen_test] async fn test_with_timeout() { - let task = - AsyncTask::<()>::pending().with_timeout(Duration::from_millis(5)); + let task = AsyncTask::<()>::pending().with_timeout(Duration::from_millis(5)); let (fut, mut rx) = task.into_parts(); assert_eq!(None, rx.try_recv());