You are developing a document approval workflow using Azure Durable Functions in C# (.NET Isolated). The workflow must wait for an external approval event named `DocumentApproved` for up to hours. If the event is received within hours, the document is processed. If the -hour limit is reached without receiving the event, the document must be marked as expired. You write the following orchestrator function code:
csharp
[Function("ApprovalOrchestrator")]
public static async Task Run(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
var approvalTask = context.WaitForExternalEvent<bool>("DocumentApproved");
var timeoutTask = Task.Delay(TimeSpan.FromHours(24));
var completedTask = await Task.WhenAny(approvalTask, timeoutTask);
if (completedTask == approvalTask)
{
bool isApproved = approvalTask.Result;
await context.CallActivityAsync("ProcessDocument", isApproved);
}
else
{
await context.CallActivityAsync("ExpireDocument", null);
}
}
Which of the following describes the defect in this orchestrator code?
- AThe `context.WaitForExternalEvent` method must be executed within a try-catch block to handle the `TimeoutException` thrown by the event listener.
- BDurable Functions do not support waiting for external events and timers simultaneously; you must split them into two separate sub-orchestrations.
- The use of `Task.Delay` violates the determinism constraint of orchestrator functions; you should use `context.CreateTimer` instead.Answer
- DThe orchestrator must use `Task.WaitAny` instead of `Task.WhenAny` because `Task.WhenAny` executes asynchronously and bypasses the state replay logic.