percy_preview_app/app/world/resources/
async_task_spawner.rs

1//! Spawn async tasks.
2
3use std::future::Future;
4use std::pin::Pin;
5
6/// Used to run an async function.
7///
8/// In the browser this will typically schedule the future to be called on the next tick of
9/// the JS microtask queue.
10///
11/// Outside of JS this will often spawn the task in a thread.
12pub trait AsyncTaskSpawner: Send + Sync {
13    /// Run an async function, typically in another thread or, if in the browser, on another tick
14    /// of the JS event loop.
15    fn spawn(&self, task: AsyncFnToSpawn);
16}
17
18/// The async task to run.
19pub type AsyncFnToSpawn = Pin<Box<dyn Future<Output = ()> + 'static>>;