Function lambda_runtime::streaming::channel
source · pub fn channel() -> (Sender, Body)
Expand description
Create a new Body
stream with associated Sender half.
Examples
use lambda_runtime::{
streaming::{channel, Body, Response},
Error, LambdaEvent,
};
use std::{thread, time::Duration};
async fn func(_event: LambdaEvent<serde_json::Value>) -> Result<Response<Body>, Error> {
let messages = vec!["Hello", "world", "from", "Lambda!"];
let (mut tx, rx) = channel();
tokio::spawn(async move {
for message in messages.iter() {
tx.send_data((message.to_string() + "\n").into()).await.unwrap();
thread::sleep(Duration::from_millis(500));
}
});
Ok(Response::from(rx))
}