Tiny Async Wasi Preview 2 Runtime
wasm wasi preview2 async runtime rust
at master 29 lines 800 B view raw
1use std::time::Duration; 2 3use tiny_wasm_runtime::{Timer, WasmRuntimeAsyncEngine}; 4 5fn main() { 6 let outcome = WasmRuntimeAsyncEngine::block_on(async { 7 let worker = WasmRuntimeAsyncEngine::spawn(async { 8 Timer::sleep(Duration::from_millis(30)).await; 9 40 10 }); 11 12 let status = Timer::timeout( 13 async { 14 Timer::sleep(Duration::from_millis(10)).await; 15 "quick-task" 16 }, 17 Duration::from_millis(100), 18 ) 19 .await 20 .expect("quick task should finish before the timeout"); 21 22 let worker_result = worker.await; 23 24 format!("{status}:{worker_result}") 25 }); 26 27 assert_eq!(outcome, "quick-task:40"); 28 println!("runtime example finished successfully: {outcome}"); 29}