Skip to main content

pebble/rendering/
async_init.rs

1use crate::{
2    prelude::{Backend, GPUSurfaceHandle},
3    rendering::sync::{InitReceiver, InitSender},
4};
5
6/// Extension of [`Backend`] for backends that initialise asynchronously.
7///
8/// # Deprecated
9/// The [`Backend`] trait now unifies native and web initialisation via its
10/// [`init`](Backend::init) method and the [`InitSender`] channel. Prefer
11/// implementing `Backend::init` directly; this trait is kept for compatibility
12/// and may be removed in a future release.
13#[deprecated = "Backend::init now handles both native and web; implement that directly instead"]
14pub trait AsyncInit: Backend {
15    /// Begin async initialisation. Deliver the finished backend through `sender`.
16    fn init_async(handle: impl GPUSurfaceHandle, width: u32, height: u32, sender: InitSender<Self>);
17}
18
19/// Holds the [`InitReceiver`] while waiting for an async backend to finish
20/// initialising. Removed from the world once the backend arrives.
21pub(crate) struct PendingBackend<B: Backend> {
22    pub(crate) receiver: std::sync::Mutex<InitReceiver<B>>,
23}