MCPcopy Create free account
hub / github.com/aws/aws-lambda-rust-runtime / stream_words

Function stream_words

examples/http-axum-streaming/src/main.rs:41–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39}
40
41async fn stream_words() -> Result<Response, AppError> {
42 let (tx, rx) = mpsc::channel::<Result<Bytes, Infallible>>(8);
43 let body = Body::from_stream(ReceiverStream::new(rx));
44
45 tokio::spawn(async move {
46 for msg in ["Hello", "world", "from", "Lambda!"] {
47 tokio::time::sleep(Duration::from_millis(500)).await;
48 if tx.send(Ok(Bytes::from(format!("{msg}\n")))).await.is_err() {
49 break;
50 }
51 }
52 });
53
54 Ok(Response::builder()
55 .status(StatusCode::OK)
56 .header(CONTENT_TYPE, "text/plain; charset=utf-8")
57 .header(CACHE_CONTROL, "no-cache")
58 .body(body)?)
59}
60
61#[tokio::main]
62async fn main() -> Result<(), Error> {

Callers

nothing calls this directly

Calls 1

sendMethod · 0.80

Tested by

no test coverage detected