Checkpoint
This commit is contained in:
parent
56fba5541a
commit
b6e4208ea8
2 changed files with 15 additions and 6 deletions
|
@ -219,7 +219,7 @@ impl AppContext {
|
||||||
f: impl FnOnce(&mut MainThread<AppContext>) -> F + Send + 'static,
|
f: impl FnOnce(&mut MainThread<AppContext>) -> F + Send + 'static,
|
||||||
) -> Task<R>
|
) -> Task<R>
|
||||||
where
|
where
|
||||||
F: Future<Output = R> + Send + 'static,
|
F: Future<Output = R> + 'static,
|
||||||
R: Send + 'static,
|
R: Send + 'static,
|
||||||
{
|
{
|
||||||
let this = self.this.upgrade().unwrap();
|
let this = self.this.upgrade().unwrap();
|
||||||
|
|
|
@ -77,13 +77,22 @@ impl Executor {
|
||||||
/// closure returns a future which will be run to completion on the main thread.
|
/// closure returns a future which will be run to completion on the main thread.
|
||||||
pub fn spawn_on_main<F, R>(&self, func: impl FnOnce() -> F + Send + 'static) -> Task<R>
|
pub fn spawn_on_main<F, R>(&self, func: impl FnOnce() -> F + Send + 'static) -> Task<R>
|
||||||
where
|
where
|
||||||
F: Future<Output = R> + Send + 'static,
|
F: Future<Output = R> + 'static,
|
||||||
R: Send + 'static,
|
R: Send + 'static,
|
||||||
|
{
|
||||||
|
let (runnable, task) = async_task::spawn(
|
||||||
|
{
|
||||||
|
let this = self.clone();
|
||||||
|
async move {
|
||||||
|
let task = this.spawn_on_main_local(func());
|
||||||
|
task.await
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
let dispatcher = self.dispatcher.clone();
|
let dispatcher = self.dispatcher.clone();
|
||||||
let (runnable, task) = async_task::spawn(async move { func().await }, move |runnable| {
|
move |runnable| dispatcher.dispatch_on_main_thread(runnable)
|
||||||
dispatcher.dispatch_on_main_thread(runnable)
|
},
|
||||||
});
|
);
|
||||||
runnable.schedule();
|
runnable.schedule();
|
||||||
Task::Spawned(task)
|
Task::Spawned(task)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue