Can you create infinite workflows with hooks and for await?

HEAD
8e87b24fix(@workflow/ai): support provider-executed tools (AI SDK v6) (#734)
This post might have stale content, as HEAD is 1010 commits ahead.

you can create infinite workflows, using hooks + for await ..., right?

is that pattern recommended? it's pretty cool, the only thing i worry about is related to error handling and retries: if a step fails, it can't be skipped, right?

Avatar of julianbenegas
Julian Benegas
commented

what about this?

export async function infiniteWorkflow() {
  "use workflow";

  const hook = createHook<{ message: string }>();

  for await (const payload of hook) {
    // This loop runs indefinitely, receiving events one by one
    await processMessage(payload.message).catch(e => {
 if (e instanceof FatalError) {
   return
 } else {
   throw e
 }
});
    
    if (payload.message === "stop") {
      break; // Only way to exit
    }
  }
}

END OF POST

Can you create infinite workflows with hooks and for await? — vercel/workflow