Skip to content

Commit beb9632

Browse files
committed
change ticker to use reference
1 parent 34fd7a3 commit beb9632

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

crates/bevy_tasks/src/thread_executor.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use futures_lite::Future;
2121
/// // create some owned values that can be moved into another thread
2222
/// let thread_executor_clone = thread_executor.clone();
2323
/// let count_clone = count.clone();
24-
/// let thread_spawner = thread_executor.spawner();
2524
///
2625
/// std::thread::scope(|scope| {
2726
/// scope.spawn(|| {
@@ -30,7 +29,7 @@ use futures_lite::Future;
3029
/// assert!(not_thread_ticker.is_none());
3130
///
3231
/// // but we can spawn tasks from another thread
33-
/// thread_spawner.spawn(async move {
32+
/// thread_executor_clone.spawn(async move {
3433
/// count_clone.fetch_add(1, Ordering::Relaxed);
3534
/// }).detach();
3635
/// });
@@ -74,10 +73,10 @@ impl<'a> ThreadExecutor<'a> {
7473
/// Use this to tick the executor.
7574
/// It only returns the ticker if it's on the thread the executor was created on
7675
/// and returns `None` otherwise.
77-
pub fn ticker(&self) -> Option<ThreadExecutorTicker<'a>> {
76+
pub fn ticker<'b>(&'b self) -> Option<ThreadExecutorTicker<'a, 'b>> {
7877
if thread::current().id() == self.thread_id {
7978
return Some(ThreadExecutorTicker {
80-
executor: self.executor.clone(),
79+
executor: &*self.executor,
8180
_marker: PhantomData::default(),
8281
});
8382
}
@@ -89,12 +88,12 @@ impl<'a> ThreadExecutor<'a> {
8988
/// make progress unless it is manually ticked on the thread it was
9089
/// created on.
9190
#[derive(Debug)]
92-
pub struct ThreadExecutorTicker<'a> {
93-
executor: Arc<Executor<'a>>,
91+
pub struct ThreadExecutorTicker<'a, 'b> {
92+
executor: &'b Executor<'a>,
9493
// make type not send or sync
9594
_marker: PhantomData<*const ()>,
9695
}
97-
impl<'a> ThreadExecutorTicker<'a> {
96+
impl<'a, 'b> ThreadExecutorTicker<'a, 'b> {
9897
/// Tick the thread executor.
9998
pub async fn tick(&self) {
10099
self.executor.tick().await;

0 commit comments

Comments
 (0)