Stream: general

Topic: tinygo and pollable


view this post on Zulip Joel (Oct 15 2025 at 22:11):

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?

view this post on Zulip Joel (Oct 15 2025 at 22:30):

correction: not 0.20, but 0.2.0

view this post on Zulip Joel Dice (Oct 15 2025 at 22:48):

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.

view this post on Zulip Joel (Oct 15 2025 at 22:52):

Oh that makes sense. This means there is no way to do multiple polls in wasip2?

view this post on Zulip Joel Dice (Oct 15 2025 at 22:52):

No, not concurrently.

view this post on Zulip Joel Dice (Oct 15 2025 at 22:57):

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.

view this post on Zulip Joel (Oct 16 2025 at 00:27):

Thanks @Joel Dice . So, I will give a "designated poller" a try.

view this post on Zulip Notification Bot (Oct 16 2025 at 00:27):

Joel has marked this topic as resolved.

view this post on Zulip Notification Bot (Oct 16 2025 at 00:30):

Joel has marked this topic as unresolved.


Last updated: Dec 06 2025 at 05:03 UTC