wasmtime
wasmtime copied to clipboard
Interruptible timeout in wasm
I want to wait / sleep or run a function after timeout of some seconds in wasm32-wasi component ? But I want that to be cancellable . I tried doing this - https://stackoverflow.com/a/70121550 But I got error - failed to spawn thread: Error { kind: Unsupported, message: "operation not supported on this platform" } on spawning thread , I have tried compiling my rust to wasm32-wasip1-threads and on host I have make sure to enable wasm_threads support by config.wasm_threads(true).
What else do I need to do ?
If you're the host then you can use Wasmtime's async support in conjunction with epochs or fuel to interrupt WebAssembly that's currently executing.
If you're the guest then the main way to block right now is through the "poll"-style interfaces which have a timeout parameter. You'll need to coordinate within the guest to ensure that this timeout is configured accordingly.
Could you explain more please ? If you can provide some documentations and demo github examples that will be great . I was expecting on guest side interrupt but I saw here - https://github.com/dicej/component-async-demo that @dicej has been using his local fork of wasmtime and other wasm tools (wit-bindgen , wasm-tools , wasmtime-wasi) . So I thought may be the async thing is not ready and not available right now . Also I am using right now 19 version of wasmtime and related tools (wasmtime-wasi , wasm-tools and so on) although I can try upgrading it to latest version if needed
Implementing a cancellable timeout should be doable with WASI 0.2 using wasi:io/poll (i.e. you shouldn't need any of the WASI 0.3 stuff I'm currently working on, and that's not ready for production use yet anyway).
The main question to answer is: what event(s) should trigger cancellation? That will determine what kind of pollables you'll pass to the poll function in addition to the monotonic-clock.subscribe_duration pollable that represents the timeout. Should it be readability on a TCP socket? Progress on an outgoing HTTP request? Something else? All of the above?
I believe the question here has been answered so I'm going to close, but feel free to comment and/or open a new issue with other questions.