[][src]Struct wasi_worker::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


impl ServiceWorker[src]

pub fn initialize(options: ServiceOptions) -> Result<()>[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>)[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>[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<()>[src]

Post message to external consumers

Example usage:

use wasi_worker::ServiceWorker;

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

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

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

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

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

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

type Error = Infallible

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.