pub struct PlatformHost { /* private fields */ }Expand description
The platform APIs available to one document, at one origin.
Construct with PlatformHost::new, hold it for the life of the document,
and drain it with take_ready.
Implementations§
Source§impl PlatformHost
impl PlatformHost
pub fn new( origin: OriginKey, fetch_provider: Arc<dyn FetchProvider>, storage_provider: Arc<dyn StorageProvider>, ) -> Self
Sourcepub fn with_waker(self, waker: ReadyWaker) -> Self
pub fn with_waker(self, waker: ReadyWaker) -> Self
Install the callback that says “a response is ready to drain”.
It runs on whatever thread the provider answered on, so it must do the minimum: set a flag, or ask a window for a frame. It must not take the document, and it must not call back into this host.
pub fn counters(&self) -> PlatformCounters
Sourcepub fn start_fetch(&self, request: FetchRequest) -> RequestId
pub fn start_fetch(&self, request: FetchRequest) -> RequestId
Begin a request. Returns immediately.
The returned id names the request until release is
called on it. It is not a promise and it does not carry a result: the
result arrives in the ready queue, which is the only place a completion
is ever observed.
Sourcepub fn take_ready(&self) -> Vec<RequestId>
pub fn take_ready(&self) -> Vec<RequestId>
Every request that has completed since the last call, and no others.
Call this with no document borrow held. The whole point of the queue
is that a caller chooses the moment, and the moment must be one where it
is safe to run guest code. Each id remains valid, and its response
readable, until release.
Sourcepub fn state(&self, id: RequestId) -> FetchState
pub fn state(&self, id: RequestId) -> FetchState
What happened to a request.
Sourcepub fn with_response<T>(
&self,
id: RequestId,
read: impl FnOnce(&FetchResponse) -> T,
) -> Option<T>
pub fn with_response<T>( &self, id: RequestId, read: impl FnOnce(&FetchResponse) -> T, ) -> Option<T>
Read something out of a completed response without cloning it.
A closure rather than a returned reference because the response lives
behind a lock, and handing a &FetchResponse out would mean handing the
guard out with it. The Option is None when the id is unknown or the
request did not produce a response.
Sourcepub fn release(&self, id: RequestId) -> bool
pub fn release(&self, id: RequestId) -> bool
Forget a request.
Valid at any point, including while still pending: the completion handler holds only an id and finds nothing to write into, so a late answer is dropped rather than resurrecting the entry. That is what makes tearing down a document with requests in flight safe.
Sourcepub fn tracked_requests(&self) -> usize
pub fn tracked_requests(&self) -> usize
How many requests are known to this host, pending or completed.