()
| 83 | |
| 84 | #[tokio::main] |
| 85 | async fn main() -> Result<(), Error> { |
| 86 | tracing::init_default_subscriber(); |
| 87 | let (request_done_sender, request_done_receiver) = unbounded_channel::<()>(); |
| 88 | |
| 89 | let flush_extension = Arc::new(FlushExtension::new(request_done_receiver)); |
| 90 | let extension = Extension::new() |
| 91 | // Internal extensions only support INVOKE events. |
| 92 | .with_events(&["INVOKE"]) |
| 93 | .with_events_processor(service_fn(|event| { |
| 94 | let flush_extension = flush_extension.clone(); |
| 95 | async move { flush_extension.invoke(event).await } |
| 96 | })) |
| 97 | // Internal extension names MUST be unique within a given Lambda function. |
| 98 | .with_extension_name("internal-flush") |
| 99 | // Extensions MUST be registered before calling lambda_runtime::run(), which ends the Init |
| 100 | // phase and begins the Invoke phase. |
| 101 | .register() |
| 102 | .await?; |
| 103 | |
| 104 | let handler = Arc::new(EventHandler::new(request_done_sender)); |
| 105 | |
| 106 | tokio::try_join!( |
| 107 | // always poll the handler function first before the flush extension, |
| 108 | // this results in a smaller future due to not needing to track which was polled first |
| 109 | // each time, and also a tiny latency savings |
| 110 | biased; |
| 111 | lambda_runtime::run(service_fn(|event| { |
| 112 | let handler = handler.clone(); |
| 113 | async move { handler.invoke(event).await } |
| 114 | })), |
| 115 | extension.run(), |
| 116 | )?; |
| 117 | |
| 118 | Ok(()) |
| 119 | } |
nothing calls this directly
no test coverage detected