Skip to main content

PlatformHost

Struct PlatformHost 

Source
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

Source

pub fn new( origin: OriginKey, fetch_provider: Arc<dyn FetchProvider>, storage_provider: Arc<dyn StorageProvider>, ) -> Self

Source

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.

Source

pub fn origin(&self) -> &OriginKey

The origin every storage call on this host is scoped to.

Source

pub fn counters(&self) -> PlatformCounters

Source

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.

Source

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.

Source

pub fn state(&self, id: RequestId) -> FetchState

What happened to a request.

Source

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.

Source

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.

Source

pub fn tracked_requests(&self) -> usize

How many requests are known to this host, pending or completed.

Source

pub fn storage_get(&self, key: &str) -> Option<String>

Source

pub fn storage_set(&self, key: &str, value: &str) -> Result<(), StorageError>

Source

pub fn storage_remove(&self, key: &str)

Source

pub fn storage_clear(&self)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.