Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fair-dolls-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aws/lambda-invoke-store": patch
---

Added an optional boolean argument that allows forcing the use of InvokeStoreMulti with AsyncLocalStorage.
9 changes: 9 additions & 0 deletions src/invoke-store.force-multi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { describe, it, expect } from "vitest";
import { InvokeStore } from "./invoke-store.js";

describe("forceInvokeStoreMulti", () => {
it("should create InvokeStoreMulti when forceInvokeStoreMulti is true, without env var", async () => {
const store = await InvokeStore.getInstanceAsync(true);
expect(store.constructor.name).toBe("InvokeStoreMulti");
});
});
4 changes: 2 additions & 2 deletions src/invoke-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ class InvokeStoreMulti extends InvokeStoreBase {
export namespace InvokeStore {
let instance: Promise<InvokeStoreBase> | null = null;

export async function getInstanceAsync(): Promise<InvokeStoreBase> {
export async function getInstanceAsync(forceInvokeStoreMulti?: boolean): Promise<InvokeStoreBase> {
if (!instance) {
// Lock synchronously on first invoke by immediately assigning the promise
instance = (async () => {
const isMulti = "AWS_LAMBDA_MAX_CONCURRENCY" in process.env;
const isMulti = forceInvokeStoreMulti === true || "AWS_LAMBDA_MAX_CONCURRENCY" in process.env;
const newInstance = isMulti
? await InvokeStoreMulti.create()
: new InvokeStoreSingle();
Expand Down
Loading