``` import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from "cloudflare:workers"; export cl
Is the
mySharedStepBetweenWorkflows a valid way to have steps be defined in a Workflow?import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from "cloudflare:workers";
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
await step.do("my first step", async () => {})
}
}
async function mySharedStepBetweenWorkflows (step: WorkflowStep) {
await step.do("my shared step", async () => {})
}mySharedStepBetweenWorkflowsawait step.do(name, mySharedFunc) 

event.instanceId (https://developers.cloudflare.com/workflows/build/workers-api/#workflowevent)

Workflow.run() function ina try / catch block? BigInt? Uncaught (in promise) TypeError: Do not know how to serialize a BigIntwaitForEvent in terms of promises?Promise.race likePromise.all would also work? bunchOfWaitForEvntsbunchOfWaitForEvntsinstance.sendEvent() with their ID.Promise.all works - we don’t change how the standard promise handling works. sendEvent is still a sub-request though.sendEventis still a sub-request though
.sendEvent (with unique Ids)Error: (workflow.invalid_event_type) Provided event type is invalid, and it was because it doesn't work with long-ish event names. I was using a UUID as the event name, and it wasn't working...step.waitForEvent("name", { type: "here" }) instance.sendEvent({ type: "here" }), that's where it was throwing the errorawait step.do(name, mySharedFunc)event.instanceIdexport default {
fetch: app.fetch,
async scheduled(controller: ScheduledController, env: Env, ctx: ExecutionContext) {
env.PROCESS_NOTION_STATUS.create();
env.PROCESS_NOTION_RELEASE.create();
},
};Workflow.run()BigIntUncaught (in promise) TypeError: Do not know how to serialize a BigIntwaitForEventPromise.racePromise.allPromise.allbunchOfWaitForEvntsbunchOfWaitForEvntsinstance.sendEvent()sendEventsendEvent.sendEventError: (workflow.invalid_event_type) Provided event type is invalidstep.waitForEvent("name", { type: "here" })instance.sendEvent({ type: "here" })export class MyWorkflow extends WorkflowEntrypoint {
let someState = await step.do('define-state', async() => ....)
while (x of someState) {
await step.do('some execution', async() => ...)
step.sleep('xxx', '1 day') // or enough time to hibernate for example
someState = await step.do('re-define state', async() => ...) // this sets someState to false
}
await step.do('we end the flow', async () => ...)
}let value = Promise.race([
step.waitForEvent("payment success", { type: "payment-success-webhook", timeout: "4 hours" ),
step.waitForEvent("payment failure", { type: "payment-failure-webhook", timeout: "4 hours" ),
])const longArray: { id: string, data: any }[] = [
/* imagine a lot of things here */
...
]
const bunchOfWaitForEvnts = longArray.map(item => step.waitForEvent("sub-workflow", { type: `id-${item.id}`, timeout: "4 hours" ))
const aggregatedResponses = Promise.all(bunchOfWaitForEvnts)
await step.do('do-more-stuff-with-aggregated-responses', async () => { /* */})