INNER CODE UNIT · Rust
handle_stream
cloudflare/workers-rs · benchmark/src/lib.rs:17
async fn handle_stream() -> Result<Response> {
use futures_util::stream;
// Create 1MB of data (1024 * 1024 bytes)
let chunk_size = 8192; // 8KB chunks
let num_chunks = (1024 * 1024) / chunk_size; // 128 chunks
let chunk = vec![b'x'; chunk_size];
// Create a stream that yields the data
let data_stream =
stream::iter((0..num_chunks).map(move |_| Ok::<Vec<u8>, worker::Error>(chunk.clone())));
Response::from_stream(data_stream)
}
/// Main benchmark handler that makes 10 parallel sub-requests
async fn handle_benchmark(url: &Url) -> Result<Response> {
// Get the base URL from the request