@@ -31,23 +31,26 @@ public void StopAndInitiateDurableTaskOrReplay(
3131 var scheduledHistoryEvent = task . GetScheduledHistoryEvent ( context ) ;
3232 var completedHistoryEvent = task . GetCompletedHistoryEvent ( context , scheduledHistoryEvent ) ;
3333
34- // Assume that the task scheduled must have completed if NoWait is not present and the orchestrator restarted
35- if ( scheduledHistoryEvent == null )
36- {
37- InitiateAndWaitForStop ( context ) ;
38- }
39-
34+ // We must check if the task has been completed first, otherwise external events will always wait upon replays
4035 if ( completedHistoryEvent != null )
4136 {
4237 CurrentUtcDateTimeUpdater . UpdateCurrentUtcDateTime ( context ) ;
43-
44- scheduledHistoryEvent . IsProcessed = true ;
45- completedHistoryEvent . IsProcessed = true ;
4638
4739 if ( GetEventResult ( completedHistoryEvent ) != null )
4840 {
4941 output ( GetEventResult ( completedHistoryEvent ) ) ;
5042 }
43+
44+ if ( scheduledHistoryEvent != null )
45+ {
46+ scheduledHistoryEvent . IsProcessed = true ;
47+ }
48+
49+ completedHistoryEvent . IsProcessed = true ;
50+ }
51+ else if ( scheduledHistoryEvent == null )
52+ {
53+ InitiateAndWaitForStop ( context ) ;
5154 }
5255 }
5356 }
@@ -69,7 +72,11 @@ public void WaitAll(
6972 break ;
7073 }
7174
72- scheduledHistoryEvent . IsProcessed = true ;
75+ if ( scheduledHistoryEvent != null )
76+ {
77+ scheduledHistoryEvent . IsProcessed = true ;
78+ }
79+
7380 completedHistoryEvent . IsProcessed = true ;
7481 completedEvents . Add ( completedHistoryEvent ) ;
7582 }
@@ -108,11 +115,13 @@ public void WaitAny(
108115 var scheduledHistoryEvent = task . GetScheduledHistoryEvent ( context ) ;
109116 var completedHistoryEvent = task . GetCompletedHistoryEvent ( context , scheduledHistoryEvent ) ;
110117
118+ // We must mark this event as processed even if it has not completed; subsequent completed history events
119+ // corresponding to an awaited task will not have their IsProcessed value ever set to true.
111120 if ( scheduledHistoryEvent != null )
112121 {
113122 scheduledHistoryEvent . IsProcessed = true ;
114123 }
115-
124+
116125 if ( completedHistoryEvent != null )
117126 {
118127 completedTasks . Add ( task ) ;
@@ -149,10 +158,17 @@ public void Stop()
149158
150159 private static object GetEventResult ( HistoryEvent historyEvent )
151160 {
152- // Output the result if and only if the history event is a completed activity function
153- return historyEvent . EventType != HistoryEventType . TaskCompleted
154- ? null
155- : TypeExtensions . ConvertFromJson ( historyEvent . Result ) ;
161+ // Output the result if and only if the history event is a completed activity function or a raised external event
162+
163+ if ( historyEvent . EventType == HistoryEventType . TaskCompleted )
164+ {
165+ return TypeExtensions . ConvertFromJson ( historyEvent . Result ) ;
166+ }
167+ else if ( historyEvent . EventType == HistoryEventType . EventRaised )
168+ {
169+ return TypeExtensions . ConvertFromJson ( historyEvent . Input ) ;
170+ }
171+ return null ;
156172 }
157173
158174 private void InitiateAndWaitForStop ( OrchestrationContext context )
0 commit comments