[][src]Struct wasi_worker_yew::ServiceWorker

pub struct ServiceWorker { /* fields omitted */ }

Connects Rust Handler with browser service worker via WASI filesystem.

ServiceWorker is a singleton which holds input and output file handles and owns woker via Handler trait. Worker is supposedly reactive, usually operating on incoming events (on_message) and posting messages to main browser application via ServiceWorker::post_message().

Note: ServiceWorker supposed to operate in single threaded environment like a browser service worker.

TODO: it requires cleaning of filesystem, add drop implementation

Methods

impl ServiceWorker[src]

pub fn initialize(options: ServiceOptions) -> Result<(), Error>[src]

Initialize ServiceWorker instance. ServiceWorker operates as singleton, all struct methods are static. Unless initialized all methods will result in error io::ErrorKind::NotConnected.

pub fn set_message_handler(new_handler: Box<dyn Handler + 'static>)[src]

Message handler is required to process incoming messages. Please note, there is no queue therefore messages received before handler initialized will be lost.

pub fn on_message() -> Result<usize, Error>[src]

This method is a trigger This is workaround while we don't have wasi::poll_oneoff, ideally we shall just poll and wait for FD_READ event.

pub fn post_message(msg: &[u8]) -> Result<(), Error>[src]

Post message to external consumers

Example usage:

use wasi_worker::ServiceWorker;
ServiceWorker::post_message(b"mymesage");

pub fn kill()[src]

Trait Implementations

impl Drop for ServiceWorker[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.