pub trait VirtualTaskManager: Debug + Send + Sync + 'static {
    // Required methods
    fn sleep_now(
        &self,
        time: Duration
    ) -> Pin<Box<dyn Future<Output = ()> + Send + Sync + 'static>>;
    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: TaskWasm<'_, '_>) -> Result<(), WasiThreadError>;
    fn task_dedicated(
        &self,
        task: Box<dyn FnOnce() + Send + 'static>
    ) -> Result<(), WasiThreadError>;
    fn thread_parallelism(&self) -> Result<usize, WasiThreadError>;

    // Provided method
    fn build_memory(
        &self,
        store: &mut StoreMut<'_>,
        spawn_type: SpawnMemoryType<'_>
    ) -> Result<Option<Memory>, WasiThreadError> { ... }
}
Expand description

An implementation of task management

Required Methods§

source

fn sleep_now( &self, time: Duration ) -> Pin<Box<dyn Future<Output = ()> + Send + Sync + 'static>>

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: TaskWasm<'_, '_>) -> Result<(), WasiThreadError>

Starts an WebAssembly task will will run on a dedicated thread pulled from the worker pool that has a stateful thread local variable

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

Provided Methods§

source

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

Build a new Webassembly memory.

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

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§

source§

impl VirtualTaskManager for TokioTaskManager

source§

impl<D, T> VirtualTaskManager for Dwhere D: Deref<Target = T> + Debug + Send + Sync + 'static, T: VirtualTaskManager + ?Sized,