pub trait VirtualTaskManager: Debug + Send + Sync + 'static {
    // Required methods
    fn build_memory(
        &self,
        store: &mut StoreMut<'_>,
        spawn_type: SpawnType
    ) -> Result<Option<Memory>, WasiThreadError>;
    fn sleep_now<'life0, 'async_trait>(
        &'life0 self,
        time: Duration
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn task_shared(
        &self,
        task: Box<dyn FnOnce() -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> + Send + 'static>
    ) -> Result<(), WasiThreadError>;
    fn runtime(&self) -> &Handle;
    fn runtime_enter<'g>(&'g self) -> Box<dyn Drop + 'g>;
    fn task_wasm(
        &self,
        task: Box<dyn FnOnce(Store, Module, Option<Memory>) + Send + 'static>,
        store: Store,
        module: Module,
        spawn_type: SpawnType
    ) -> Result<(), WasiThreadError>;
    fn task_dedicated(
        &self,
        task: Box<dyn FnOnce() + Send + 'static>
    ) -> Result<(), WasiThreadError>;
    fn thread_parallelism(&self) -> Result<usize, WasiThreadError>;
}
Expand description

An implementation of task management

Required Methods§

source

fn build_memory( &self, store: &mut StoreMut<'_>, spawn_type: SpawnType ) -> Result<Option<Memory>, WasiThreadError>

Build a new Webassembly memory.

May return None if the memory can just be auto-constructed.

source

fn sleep_now<'life0, 'async_trait>( &'life0 self, time: Duration ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Invokes whenever a WASM thread goes idle. In some runtimes (like singlethreaded execution environments) they will need to do asynchronous work whenever the main thread goes idle and this is the place to hook for that.

source

fn task_shared( &self, task: Box<dyn FnOnce() -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> + Send + 'static> ) -> Result<(), WasiThreadError>

Starts an asynchronous task that will run on a shared worker pool This task must not block the execution or it could cause a deadlock

source

fn runtime(&self) -> &Handle

Returns a runtime that can be used for asynchronous tasks

source

fn runtime_enter<'g>(&'g self) -> Box<dyn Drop + 'g>

Enters a runtime context

source

fn task_wasm( &self, task: Box<dyn FnOnce(Store, Module, Option<Memory>) + Send + 'static>, store: Store, module: Module, spawn_type: SpawnType ) -> Result<(), WasiThreadError>

Starts an asynchronous task will will run on a dedicated thread pulled from the worker pool that has a stateful thread local variable It is ok for this task to block execution and any async futures within its scope

source

fn task_dedicated( &self, task: Box<dyn FnOnce() + Send + 'static> ) -> Result<(), WasiThreadError>

Starts an asynchronous task will will run on a dedicated thread pulled from the worker pool. It is ok for this task to block execution and any async futures within its scope

source

fn thread_parallelism(&self) -> Result<usize, WasiThreadError>

Returns the amount of parallelism that is possible on this platform

Implementations§

source§

impl dyn VirtualTaskManager

source

pub fn block_on<'a, A>(&self, task: impl Future<Output = A> + 'a) -> A

Execute a future and return the output. This method blocks until the future is complete.

Implementors§