@@ -131,7 +131,7 @@ where
131
131
///
132
132
/// You can use this future to execute cleanup or flush related logic prior to runtime shutdown.
133
133
///
134
- /// This function must be called prior to [lambda_runtime::run()].
134
+ /// This function's returned future must be resolved prior to [lambda_runtime::run()].
135
135
///
136
136
/// Note that this implicitly also registers and drives a no-op internal extension that subscribes to no events.
137
137
/// This extension will be named `_lambda-rust-runtime-no-op-graceful-shutdown-helper`. This extension name
@@ -166,7 +166,7 @@ where
166
166
/// let shutdown_hook = || async move {
167
167
/// std::mem::drop(log_guard);
168
168
/// };
169
- /// lambda_runtime::spawn_graceful_shutdown_handler(shutdown_hook);
169
+ /// lambda_runtime::spawn_graceful_shutdown_handler(shutdown_hook).await ;
170
170
///
171
171
/// lambda_runtime::run(func).await?;
172
172
/// Ok(())
@@ -178,29 +178,29 @@ where
178
178
/// ```
179
179
#[ cfg( all( unix, feature = "graceful-shutdown" ) ) ]
180
180
#[ cfg_attr( docsrs, doc( cfg( all( unix, feature = "tokio-rt" ) ) ) ) ]
181
- pub fn spawn_graceful_shutdown_handler < Fut > ( shutdown_hook : impl FnOnce ( ) -> Fut + Send + ' static )
181
+ pub async fn spawn_graceful_shutdown_handler < Fut > ( shutdown_hook : impl FnOnce ( ) -> Fut + Send + ' static )
182
182
where
183
183
Fut : Future < Output = ( ) > + Send + ' static ,
184
184
{
185
- tokio:: task:: spawn ( async move {
186
- // You need an extension registered with the Lambda orchestrator in order for your process
187
- // to receive a SIGTERM for graceful shutdown.
188
- //
189
- // We accomplish this here by registering a no-op internal extension, which does not subscribe to any events.
190
- //
191
- // This extension is cheap to run since after it connects to the lambda orchestration, the connection
192
- // will just wait forever for data to come, which never comes, so it won't cause wakes.
193
- let extension = lambda_extension:: Extension :: new ( )
194
- // Don't subscribe to any event types
195
- . with_events ( & [ ] )
196
- // Internal extension names MUST be unique within a given Lambda function.
197
- . with_extension_name ( "_lambda-rust-runtime-no-op-graceful-shutdown-helper" )
198
- // Extensions MUST be registered before calling lambda_runtime::run(), which ends the Init
199
- // phase and begins the Invoke phase.
200
- . register ( )
201
- . await
202
- . expect ( "could not register no-op extension for graceful shutdown" ) ;
185
+ // You need an extension registered with the Lambda orchestrator in order for your process
186
+ // to receive a SIGTERM for graceful shutdown.
187
+ //
188
+ // We accomplish this here by registering a no-op internal extension, which does not subscribe to any events.
189
+ //
190
+ // This extension is cheap to run since after it connects to the lambda orchestration, the connection
191
+ // will just wait forever for data to come, which never comes, so it won't cause wakes.
192
+ let extension = lambda_extension:: Extension :: new ( )
193
+ // Don't subscribe to any event types
194
+ . with_events ( & [ ] )
195
+ // Internal extension names MUST be unique within a given Lambda function.
196
+ . with_extension_name ( "_lambda-rust-runtime-no-op-graceful-shutdown-helper" )
197
+ // Extensions MUST be registered before calling lambda_runtime::run(), which ends the Init
198
+ // phase and begins the Invoke phase.
199
+ . register ( )
200
+ . await
201
+ . expect ( "could not register no-op extension for graceful shutdown" ) ;
203
202
203
+ tokio:: task:: spawn ( async move {
204
204
let graceful_shutdown_future = async move {
205
205
let mut sigint = tokio:: signal:: unix:: signal ( tokio:: signal:: unix:: SignalKind :: interrupt ( ) ) . unwrap ( ) ;
206
206
let mut sigterm = tokio:: signal:: unix:: signal ( tokio:: signal:: unix:: SignalKind :: terminate ( ) ) . unwrap ( ) ;
0 commit comments