diff --git a/.changeset/fair-dolls-smash.md b/.changeset/fair-dolls-smash.md new file mode 100644 index 0000000..72f6d18 --- /dev/null +++ b/.changeset/fair-dolls-smash.md @@ -0,0 +1,5 @@ +--- +"@aws/lambda-invoke-store": patch +--- + +Added an optional boolean argument that allows forcing the use of InvokeStoreMulti with AsyncLocalStorage. diff --git a/src/invoke-store.force-multi.spec.ts b/src/invoke-store.force-multi.spec.ts new file mode 100644 index 0000000..1c01e01 --- /dev/null +++ b/src/invoke-store.force-multi.spec.ts @@ -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"); + }); +}); diff --git a/src/invoke-store.ts b/src/invoke-store.ts index 8e3be43..572ea13 100644 --- a/src/invoke-store.ts +++ b/src/invoke-store.ts @@ -152,11 +152,11 @@ class InvokeStoreMulti extends InvokeStoreBase { export namespace InvokeStore { let instance: Promise | null = null; - export async function getInstanceAsync(): Promise { + export async function getInstanceAsync(forceInvokeStoreMulti?: boolean): Promise { 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();