Human-in-the-loop use case
Start a new project using a human-in-the-loop (HITL) use case example.
Problem
You want to build a system that requires human input at certain stages of the process, such as manual review or approval.
How do you suspend a business process until a human completes a task, and then resume it once the task is done?
Solution
Await a Durable Promise to block the process until the human completes their task, then resolve the Promise to resume execution.
Quick example
- TypeScript
// process x
function* foo(context: Context, workflowId: string): Generator<any, void, any> {
// create a promise
const blockingPromise = yield* context.promise();
// expose the id to the outside world
yield* context.run(sendEmail, blockingPromise.id);
console.log(`blocked, waiting on human interaction`);
// wait until the promise is resolved
yield* blockingPromise;
console.log(`unblocked, promise resolved`);
return;
}
// process y
app.get("/unblock-workflow", async (req: Request, res: Response) => {
// expose an endpoint to resolve the promise
try {
// ...
// unblock a workflow by resolving a promise
await resonate.promises.resolve(promiseId);
// ...
} catch (err: any) {
// ...
}
});