Skip to content

Commit

Permalink
change ticker to use reference
Browse files Browse the repository at this point in the history
  • Loading branch information
hymm committed Jan 10, 2023
1 parent 34fd7a3 commit beb9632
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions crates/bevy_tasks/src/thread_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use futures_lite::Future;
/// // create some owned values that can be moved into another thread
/// let thread_executor_clone = thread_executor.clone();
/// let count_clone = count.clone();
/// let thread_spawner = thread_executor.spawner();
///
/// std::thread::scope(|scope| {
/// scope.spawn(|| {
Expand All @@ -30,7 +29,7 @@ use futures_lite::Future;
/// assert!(not_thread_ticker.is_none());
///
/// // but we can spawn tasks from another thread
/// thread_spawner.spawn(async move {
/// thread_executor_clone.spawn(async move {
/// count_clone.fetch_add(1, Ordering::Relaxed);
/// }).detach();
/// });
Expand Down Expand Up @@ -74,10 +73,10 @@ impl<'a> ThreadExecutor<'a> {
/// Use this to tick the executor.
/// It only returns the ticker if it's on the thread the executor was created on
/// and returns `None` otherwise.
pub fn ticker(&self) -> Option<ThreadExecutorTicker<'a>> {
pub fn ticker<'b>(&'b self) -> Option<ThreadExecutorTicker<'a, 'b>> {
if thread::current().id() == self.thread_id {
return Some(ThreadExecutorTicker {
executor: self.executor.clone(),
executor: &*self.executor,
_marker: PhantomData::default(),
});
}
Expand All @@ -89,12 +88,12 @@ impl<'a> ThreadExecutor<'a> {
/// make progress unless it is manually ticked on the thread it was
/// created on.
#[derive(Debug)]
pub struct ThreadExecutorTicker<'a> {
executor: Arc<Executor<'a>>,
pub struct ThreadExecutorTicker<'a, 'b> {
executor: &'b Executor<'a>,
// make type not send or sync
_marker: PhantomData<*const ()>,
}
impl<'a> ThreadExecutorTicker<'a> {
impl<'a, 'b> ThreadExecutorTicker<'a, 'b> {
/// Tick the thread executor.
pub async fn tick(&self) {
self.executor.tick().await;
Expand Down

0 comments on commit beb9632

Please sign in to comment.