Skip to content

Commit a4e48d4

Browse files
committed
feat: add waitForEvent and sendEvent support for local dev
This uses some @ts-expect-errors since these are not in workers-types, yet.
1 parent 743c57d commit a4e48d4

File tree

5 files changed

+5
-12
lines changed

5 files changed

+5
-12
lines changed

fixtures/workflow/tests/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe("Workflows", () => {
139139
]);
140140
});
141141

142-
test.only("waitForEvent should work", async ({ expect }) => {
142+
test("waitForEvent should work", async ({ expect }) => {
143143
await fetchJson(`http://${ip}:${port}/createDemo2?workflowName=something`);
144144

145145
await fetchJson(

packages/workflows-shared/src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,8 @@ export class Context extends RpcTarget {
605605
(a) => a.hash === cacheKey && a.type === "timeout"
606606
);
607607
if (
608-
// @ts-expect-error priorityQueue is initiated in init
609608
(timeoutEntryPQ === undefined &&
609+
this.#engine.priorityQueue !== undefined &&
610610
this.#engine.priorityQueue.checkIfExistedInPast({
611611
hash: cacheKey,
612612
type: "timeout",

packages/workflows-shared/src/engine.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ export class Engine extends DurableObject<Env> {
7979
timeoutHandler: GracePeriodSemaphore;
8080
priorityQueue: TimePriorityQueue | undefined;
8181

82-
// eslint-disable-next-line @typescript-eslint/ban-types
83-
waiters: Map<string, Array<Function>> = new Map();
82+
waiters: Map<string, Array<(...args: unknown[]) => void>> = new Map();
8483
eventMap: Map<string, Array<Event>> = new Map();
8584

8685
constructor(state: DurableObjectState, env: Env) {
@@ -263,7 +262,6 @@ export class Engine extends DurableObject<Env> {
263262
throw new Error("Engine was never started");
264263
}
265264

266-
// @ts-expect-error event types are wrong but that's okay since we just take metadata :)
267265
void this.init(
268266
metadata.accountId,
269267
metadata.workflow,

packages/workflows-shared/src/instance.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
DatabaseVersion,
55
DatabaseWorkflow,
66
} from "./engine";
7+
import type { WorkflowEvent } from "cloudflare:workers";
78

89
export type Instance = {
910
id: string;
@@ -23,10 +24,7 @@ export type InstanceMetadata = {
2324
workflow: DatabaseWorkflow;
2425
version: DatabaseVersion;
2526
instance: DatabaseInstance;
26-
event: {
27-
payload: Record<string, unknown>;
28-
timestamp: Date;
29-
};
27+
event: WorkflowEvent<unknown>;
3028
};
3129

3230
export enum InstanceStatus {

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)