I have a WIT with a wasi:io/poll. This version is 0.2.6. However, I see that tinygo uses 0.20. When I call Block() on the pollable object generated from my WIT file, it blocks execution of all my goroutines. Do I have to do something special to use the pollable object understood by tinygo so that a Block call does not lock up my program?
correction: not 0.20, but 0.2.0
My understanding is that TinyGo uses Asyncify to implement goroutines. One limitation of that approach is that any call to an imported function (such as wasi:io/poll#pollable.block) will effectively suspend all goroutines until the call returns given that no Wasm code in the instance can run in the interim.
I don't expect that will be addressed for WASIp2, but my hope is that with WASIp3 (which is based on a new Component Model async ABI), we'll be able to hook into TinyGo's Asyncify transformation (and, in the case of "big" Go, the equivalent transformation it does at the IR level before emitting Wasm code) and transparently suspend and resume goroutines as they are blocked and unblocked on I/O, respectively -- while still allowing unblocked goroutines to make progress. I'm specifically planning to create a proof-of-concept demonstrating this for "big" Go when I have a chance, but I'm not sure when that will be.
Eventually, once the TinyGo and "big" Go toolchains have embraced some flavor of Wasm stack switching, these Asyncify-style transformations will no longer be necessary, at which point we'll have a Go concurrency story that's both idiomatic and efficient. That will be a bigger effort requiring more coordination, though.
Oh that makes sense. This means there is no way to do multiple polls in wasip2?
No, not concurrently.
Hypothetically, you could arrange for one of your goroutines to be the "designated poller", calling poll only once all the other goroutines have submitted the pollables they're interested in, e.g. via a channel.
Thanks @Joel Dice . So, I will give a "designated poller" a try.
Joel has marked this topic as resolved.
Joel has marked this topic as unresolved.
Last updated: Dec 06 2025 at 05:03 UTC