Tiny Async Wasi Preview 2 Runtime
wasm wasi preview2 async runtime rust
at master 24 lines 614 B view raw
1use std::time::Duration; 2 3use tiny_wasm_runtime::{Timer, WasmRuntimeAsyncEngine}; 4 5#[tiny_wasm_runtime::main] 6async fn main() { 7 let handle = WasmRuntimeAsyncEngine::spawn(async { 8 Timer::sleep(Duration::from_millis(25)).await; 9 12 10 }); 11 12 let quick_result = Timer::timeout( 13 async { 14 Timer::sleep(Duration::from_millis(5)).await; 15 "macro-ready" 16 }, 17 Duration::from_millis(100), 18 ) 19 .await 20 .expect("timeout should not trigger"); 21 22 let value = handle.await; 23 println!("macro example finished successfully: {quick_result}:{value}"); 24}