Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit f01624b

Browse files
committed
Only waitUntil scheduled module handler return if defined
1 parent 5d32587 commit f01624b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

packages/core/src/standards/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ export class ServiceWorkerGlobalScope extends WorkerGlobalScope {
335335
const controller = new ScheduledController(e.scheduledTime, e.cron);
336336
const ctx = new ExecutionContext(e);
337337
const res = listener(controller, this.#bindings, ctx);
338-
e.waitUntil(Promise.resolve(res));
338+
if (res !== undefined) e.waitUntil(Promise.resolve(res));
339339
});
340340
}
341341

packages/core/test/standards/event.spec.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,25 @@ test("MiniflareCore: adds module scheduled event listener", async (t) => {
168168
return "returned";
169169
}
170170
}`;
171-
const mf = useMiniflare(
171+
let mf = useMiniflare(
172172
{ BindingsPlugin },
173173
{ modules: true, script, bindings: { KEY: "value" } }
174174
);
175-
const res = await mf.dispatchScheduled(1000, "30 * * * *");
175+
let res = await mf.dispatchScheduled(1000, "30 * * * *");
176176
t.deepEqual(res, [1000, "30 * * * *", "value", "that", "returned"]);
177+
178+
// Check returned value is only waitUntil'ed if it's defined
179+
mf = useMiniflare(
180+
{ BindingsPlugin },
181+
{
182+
modules: true,
183+
script: `export default { scheduled(controller, env, ctx) {
184+
ctx.waitUntil(42);
185+
}}`,
186+
}
187+
);
188+
res = await mf.dispatchScheduled(1000, "30 * * * *");
189+
t.deepEqual(res, [42]);
177190
});
178191

179192
test("kDispatchFetch: dispatches event", async (t) => {

0 commit comments

Comments
 (0)