Checkpoint

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2023-09-22 12:52:52 -06:00
parent e4e9da7673
commit d1791a999d
2 changed files with 8 additions and 14 deletions

View file

@ -47,9 +47,10 @@ impl App {
where where
F: 'static + FnOnce(&mut AppContext), F: 'static + FnOnce(&mut AppContext),
{ {
let this = self.clone();
let platform = self.0.lock().platform.clone(); let platform = self.0.lock().platform.clone();
platform.borrow_on_main_thread().run(Box::new(move || { platform.borrow_on_main_thread().run(Box::new(move || {
let cx = &mut *self.0.lock(); let cx = &mut *this.0.lock();
on_finish_launching(cx); on_finish_launching(cx);
})); }));
} }

View file

@ -149,19 +149,12 @@ impl<T: 'static + ?Sized> MainThreadOnly<T> {
where where
R: Send + 'static, R: Send + 'static,
{ {
let (tx, rx) = oneshot::channel(); let this = self.clone();
if self.dispatcher.is_main_thread() { crate::spawn_on_main(self.dispatcher.clone(), async move {
let _ = tx.send(f(&self.value)); // Required so we move `this` instead of this.value. Only `this` is `Send`.
} else { let this = this;
let this = self.clone(); f(&this.value)
let _ = crate::spawn_on_main(self.dispatcher.clone(), async move { })
// Required so we move `this` instead of this.value. Only `this` is `Send`.
let this = this;
let _ = tx.send(f(&this.value));
});
}
async move { rx.await.unwrap() }
} }
} }