alexcrichton opened PR #7130 from alexcrichton:refactor-subscribe to bytecodealliance:main:
This commit refactors how the
Pollableresource is created in WASI. Previously this was created manually via two variants of aPollableenum but this was somewhat error prone for a few reasons:
The more common representation,
TableEntry, had boilerplate associated with it that had dynamic downcasts and such. This is now all hidden behind a more typed API.Callers had to remember to use
push_child_resourcewhich is easy to forget.The previous signature of the readiness check returned a
Result<()>which made it accidentally easy for errors to be propagated into traps rather than being returned as a "last operation failed" error.This commit replaces the previous API with a single
subscribefunction which takes aResource<T>and returns aResource<Pollable>. TheTtype must implement a new trait,Subscribe, which indicates the asynchronous readiness check. This readiness check additionally returns()so it's no longer possible to accidentally return errors (or trap).This namely required refactoring the
HostOutputStreamtrait and implementations. The trait itself now has acheck_writemethod corresponding to to the same WASI function. The oldwrite_readyfunction is now a convenience helper combo betweenreadyandcheck_write. Concrete implementations are refactored to store errors discovered duringreadyto get communicated throughcheck-writelater on.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested pchickey for a review on PR #7130.
alexcrichton requested wasmtime-core-reviewers for a review on PR #7130.
pchickey requested elliottt for a review on PR #7130.
pchickey submitted PR review:
This is a really nice improvement given all the safety changes. Thanks!
alexcrichton merged PR #7130.
Last updated: Dec 13 2025 at 19:03 UTC