Commit 8dd4b89
authored
rust: Add support for inter-task wakeups (#1440)
* rust: Add support for inter-task wakeups
This commit fixes a preexisting issue in the async support in the rust
bindings where inter-component-model-task wakeups/communication did not
work. Previously `wit-bindgen` would end up either panicking or wedging
itself if this situation arose, effectively not handling it at all.
Inter-task wakeups are supported in the component model with unit
streams and futures (e.g. `future` and `stream` with no type parameter).
For these types the component model allows the same instance to both
read/write from the stream or future. The support here is implemented
with `stream` as a task might receive many wake up notifications over
its lifetime.
Implementing this is a bit tricky, so the highlights of the
implementation are:
* This relies on new "magic function imports" recognized by
`wit-component` specifically related to unit-streams and unit-futures.
This is a very new feature of `wit-component` and thus hasn't had time
to propagate throughout the ecosystem yet. Due to the niche nature of
needing cross-task wakeups this commit disables cross-task wakeups by
default and adds support for it behind a Cargo feature. The thinking
is that if anyone runs into this there's now a clear panic/error
message indicating that the feature can be enabled. Otherwise the hope
is that no one runs into this (as it's relatively niche) and when the
time is right we can enable this by default.
* All tasks started by wit-bindgen will need this new inter-task-wakeup
stream for the reason that we don't actually know what will wake a
task up when it blocks. To avoid adding a stream allocation on the
fast path, the allocation of the inter-task stream is deferred until
a task blocks for the first time.
* Right now a read of the inter-task stream starts when a task blocks.
The read is cancelled when the task wakes up. A future optimization
would be to keep the read-in-progress and only restart it if
necessary. For now that's deferred, however.
Closes #1431
* Update dependencies
* Review comments1 parent 369bbb0 commit 8dd4b89
File tree
14 files changed
+507
-137
lines changed- .github/workflows
- crates
- guest-rust
- src
- rt
- async_support
- test/src
- tests/runtime-async/async/rust-cross-task-wakeup
14 files changed
+507
-137
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| 192 | + | |
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
| |||
0 commit comments