import { Batcher } from "@edgefirst-dev/batcher";
// Configure the time window for the batcher
// The batcher will call the async function only once for the same key in this time window
let batcher = new Batcher<number, string>(10);
async function asyncFunction(): Promise<string> {
await new Promise((resolve) => setTimeout(resolve, 1000));
return { value: "ok" };
}
let [result1, result2] = await Promise.all([
batcher.call(["my", "custom", "key"], asyncFunction),
batcher.call(["my", "custom", "key"], asyncFunction),
]);
console.log(result1 === result2); // true