MCPcopy Index your code
hub / github.com/aws/aws-lambda-rust-runtime / main

Function main

examples/extension-internal-flush/src/main.rs:85–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

83
84#[tokio::main]
85async 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}

Callers

nothing calls this directly

Calls 7

init_default_subscriberFunction · 0.85
registerMethod · 0.80
with_extension_nameMethod · 0.80
with_events_processorMethod · 0.80
with_eventsMethod · 0.80
invokeMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected