in src/DurableSDK/DurableTaskHandler.cs [154:207]
public void WaitAny(
IReadOnlyCollection<DurableTask> tasksToWaitFor,
OrchestrationContext context,
Action<object> output)
{
context.OrchestrationActionCollector.NextBatch();
var completedTasks = new List<DurableTask>();
DurableTask firstCompletedTask = null;
int firstCompletedHistoryEventIndex = -1;
foreach (var task in tasksToWaitFor)
{
var scheduledHistoryEvent = task.GetScheduledHistoryEvent(context);
var completedHistoryEvent = task.GetCompletedHistoryEvent(context, scheduledHistoryEvent);
// We must mark this event as processed even if it has not completed; subsequent completed history events
// corresponding to an awaited task will not have their IsProcessed value ever set to true.
if (scheduledHistoryEvent != null)
{
scheduledHistoryEvent.IsProcessed = true;
scheduledHistoryEvent.IsPlayed = true;
}
if (completedHistoryEvent != null)
{
completedTasks.Add(task);
int completedHistoryEventIndex = Array.IndexOf(context.History, completedHistoryEvent);
if (firstCompletedHistoryEventIndex < 0 ||
completedHistoryEventIndex < firstCompletedHistoryEventIndex)
{
firstCompletedHistoryEventIndex = completedHistoryEventIndex;
firstCompletedTask = task;
}
completedHistoryEvent.IsProcessed = true;
completedHistoryEvent.IsPlayed = true;
}
}
var anyTaskCompleted = completedTasks.Count > 0;
if (anyTaskCompleted)
{
context.IsReplaying = context.History[firstCompletedHistoryEventIndex].IsPlayed;
CurrentUtcDateTimeUpdater.UpdateCurrentUtcDateTime(context);
// Return a reference to the first completed task
output(firstCompletedTask);
}
else
{
InitiateAndWaitForStop(context);
}
}