Skip to content

Commit f8b9a2a

Browse files
authored
chore(lambda-runtime): slightly optimize graceful shutdown helper by using new tokio::try_join biased; api (#1007)
1 parent 2278cea commit f8b9a2a

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

examples/extension-internal-flush/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ aws_lambda_events = { path = "../../lambda-events" }
99
lambda-extension = { path = "../../lambda-extension" }
1010
lambda_runtime = { path = "../../lambda-runtime" }
1111
serde = "1.0.136"
12-
tokio = { version = "1", features = ["macros", "sync"] }
12+
tokio = { version = "1.46", features = ["macros", "sync"] }

examples/extension-internal-flush/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ async fn main() -> Result<(), Error> {
101101

102102
let handler = Arc::new(EventHandler::new(request_done_sender));
103103

104-
// TODO: add biased! to always poll the handler future first, once supported:
105-
// https://github.com/tokio-rs/tokio/issues/7304
106104
tokio::try_join!(
105+
// always poll the handler function first before the flush extension,
106+
// this results in a smaller future due to not needing to track which was polled first
107+
// each time, and also a tiny latency savings
108+
biased;
107109
lambda_runtime::run(service_fn(|event| {
108110
let handler = handler.clone();
109111
async move { handler.invoke(event).await }

lambda-runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pin-project = "1"
5252
serde = { version = "1", features = ["derive", "rc"] }
5353
serde_json = "^1"
5454
serde_path_to_error = "0.1.11"
55-
tokio = { version = "1.0", features = [
55+
tokio = { version = "1.46", features = [
5656
"macros",
5757
"io-util",
5858
"sync",

lambda-runtime/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,11 @@ where
223223
}
224224
};
225225

226-
// TODO: add biased! to always poll the signal handling future first, once supported:
227-
// https://github.com/tokio-rs/tokio/issues/7304
228-
let _: (_, ()) = tokio::join!(graceful_shutdown_future, async {
226+
let _: (_, ()) = tokio::join!(
227+
// we always poll the graceful shutdown future first,
228+
// which results in a smaller future due to lack of bookkeeping of which was last polled
229+
biased;
230+
graceful_shutdown_future, async {
229231
// we suppress extension errors because we don't actually mind if it crashes,
230232
// all we need to do is kick off the run so that lambda exits the init phase
231233
let _ = extension.run().await;

0 commit comments

Comments
 (0)