Hello all :)
I would like to write a simple test to make a couple of async calls to monotonic-clock#wait_for, and wait for the first one that returns. On the low level I want to make a waitable-set and then waitable-set.join the two futures together; I assume an async function returns a future but perhaps that is a misconception. Anyway I am having trouble finding how waitable-set.join is mapped into rust and wit-bindgen. What's up?
/me summons @Till Schneidereit
it would seem that I can add a dep on wit-bindgen-rt, which has a WaitableSet binding, but it appears to be private; dunno what is going on
I'm no expert on this by any means, but I think this test shows how to use futures::join to do this?
with the runner.rs files in the other async tests having examples, too
waitable-set.join is more like adding an fd to an epoll set
it's not the actual operation to wait on the epollfd
but this points me in what is probably the right direction, i will see if i can futures::select_biased over a couple of async results
join isn't the actual wait operation either, but as I said: I'm by no means an expert on this. @Roman Volosatovs might be around and know, otherwise @Alex Crichton and @Joel Dice would certainly know, but won't be awake for another few hours
/me lunch, biab
If you are in "Rust-land", then you can treat wait_for just as a regular async fn wait_for in Rust, and treat the result value as a regular https://doc.rust-lang.org/std/future/trait.Future.html
Perhaps this wasi:clocks test could serve as a good example https://github.com/bytecodealliance/wasmtime/blob/e767c56b824e5ce8947997b052859e050419d35b/crates/test-programs/src/bin/p3_clocks_sleep.rs
so futures::select_biased should work just fine (and if it does not - that's a bug we should fix)
neat, our tests are similar https://github.com/WebAssembly/wasi-testsuite/pull/120/files#diff-0308e5f25267659be76c7a48f5e83bed5a6258d013f20502300ef18c72411407
what i am interested in testing tho is when there are multiple futures outstanding
Keep in mind you can always bypass wit-bindgen-rt's abstractions and import and call the intrinsics directly. We do that here and here, for example.
oh that's very funny, thank you for that
Part of this is where it's kind of hard to figure out what exactly you're testing. For example right now you're moreso testing tooling like wasm-component-ld than you're testing the raw component model (e.g. writing source code that's compiled vs writing *.wast). When writing Rust you're more testing the bindings in the wit-bindgen crate than the async intrinsics themselves.
Given that I feel like the best answer here is "what are you trying to test" which lends itself to an answer of how to test it. For example:
*.wast or *.watwit-bindgen and wasm-component-ld, however.asyncI realize though that not all of this is up-and-running as of this red hot second, but it's things where I would personally say it's best to avoid raw definitions of APIs where you can because that's technically an "unstable layer" which is yet more we'd have to change if we ever tweak it (vs just changing the bindings generator)
It's sufficient, but a case where C may be better suited for example
Last updated: Dec 06 2025 at 06:05 UTC