Can I combine sleep() with hooks for non-blocking scheduling?
can i combine/race a sleep() with a hook? or like, imagine an "infinite workflow" pattern in which, with some hooks, i can schedule work for later (but not blocking the "hook loop")
so cool. does calling a step in the sleep().then() work as expected and will get awaited?
like
void sleep(10_000).then(async () => { await someLongRunningStep() })
interesting.
what would happen on something like this
export async function myWorkflow() { "use workflow";
using hook = createHook
for await (const command of hook) { queue.push(command)
while (queue.length > 0) {
const event = queue.shift()
switch () {
...
// imagine in some case, we update the queue
// but after the hook is "settled" and the queue is at 0
// does the new queue item get processed?
void sleep('1d').then(() => {
queue.push({something})
});
}
}
}
return "done"; }
yeah like your self resuming pattern would work if that step got awaited. alternatively, we could start() a sibling workflow that sleeps and resumes the loop
END OF POST