Path: blob/main/crates/test-programs/src/bin/async_unit_stream_callee.rs
1693 views
mod bindings {1wit_bindgen::generate!({2path: "../misc/component-async-tests/wit",3world: "unit-stream-callee",4});56use super::Component;7export!(Component);8}910use {11bindings::{exports::local::local::unit_stream::Guest, wit_stream},12wit_bindgen::StreamReader,13};1415struct Component;1617impl Guest for Component {18async fn run(count: u32) -> StreamReader<()> {19let (mut tx, rx) = wit_stream::new();2021wit_bindgen::spawn(async move {22let mut sent = 0;23let mut chunk_size = 1;24while sent < count {25let n = (count - sent).min(chunk_size);26let remaining = tx.write_all(vec![(); usize::try_from(n).unwrap()]).await;27assert!(remaining.is_empty());28sent += n;29chunk_size *= 2;30}31});3233rx34}35}3637// Unused function; required since this file is built as a `bin`:38fn main() {}394041