lambda_runtime/streaming.rs
1pub use lambda_runtime_api_client::body::{sender::Sender, Body};
2
3pub use crate::types::StreamResponse as Response;
4
5/// Create a new `Body` stream with associated Sender half.
6///
7/// Examples
8///
9/// ```
10/// use lambda_runtime::{
11/// streaming::{channel, Body, Response},
12/// Error, LambdaEvent,
13/// };
14/// use std::{thread, time::Duration};
15///
16/// async fn func(_event: LambdaEvent<serde_json::Value>) -> Result<Response<Body>, Error> {
17/// let messages = vec!["Hello", "world", "from", "Lambda!"];
18///
19/// let (mut tx, rx) = channel();
20///
21/// tokio::spawn(async move {
22/// for message in messages.iter() {
23/// tx.send_data((message.to_string() + "\n").into()).await.unwrap();
24/// thread::sleep(Duration::from_millis(500));
25/// }
26/// });
27///
28/// Ok(Response::from(rx))
29/// }
30/// ```
31#[allow(unused)]
32#[inline]
33pub fn channel() -> (Sender, Body) {
34 Body::channel()
35}