Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/test-programs/src/bin/async_read_resource_stream.rs
1693 views
1
mod bindings {
2
wit_bindgen::generate!({
3
path: "../misc/component-async-tests/wit",
4
world: "read-resource-stream",
5
});
6
7
use super::Component;
8
export!(Component);
9
}
10
11
use bindings::{exports::local::local::run::Guest, local::local::resource_stream};
12
13
struct Component;
14
15
impl Guest for Component {
16
async fn run() {
17
let mut count = 7;
18
let mut stream = resource_stream::foo(count);
19
20
while let Some(x) = stream.next().await {
21
if count > 0 {
22
count -= 1;
23
} else {
24
panic!("received too many items");
25
}
26
27
x.foo()
28
}
29
30
if count != 0 {
31
panic!("received too few items");
32
}
33
}
34
}
35
36
// Unused function; required since this file is built as a `bin`:
37
fn main() {}
38
39