Skip to content

Commit ba3c35d

Browse files
CopilotYunchuWang
andcommitted
Refactor to reduce code duplication in WaitForExternalEvent overloads
Co-authored-by: YunchuWang <[email protected]>
1 parent 8e5013f commit ba3c35d

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

src/Abstractions/TaskOrchestrationContext.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -222,28 +222,9 @@ public virtual Task CreateTimer(TimeSpan delay, CancellationToken cancellationTo
222222
/// </param>
223223
/// <param name="timeout">The amount of time to wait before cancelling the external event task.</param>
224224
/// <inheritdoc cref="WaitForExternalEvent(string, CancellationToken)"/>
225-
public async Task<T> WaitForExternalEvent<T>(string eventName, TimeSpan timeout)
225+
public Task<T> WaitForExternalEvent<T>(string eventName, TimeSpan timeout)
226226
{
227-
// Timeouts are implemented using durable timers.
228-
using CancellationTokenSource timerCts = new();
229-
Task timeoutTask = this.CreateTimer(timeout, timerCts.Token);
230-
231-
using CancellationTokenSource eventCts = new();
232-
Task<T> externalEventTask = this.WaitForExternalEvent<T>(eventName, eventCts.Token);
233-
234-
// Wait for either task to complete and then cancel the one that didn't.
235-
Task winner = await Task.WhenAny(timeoutTask, externalEventTask);
236-
if (winner == externalEventTask)
237-
{
238-
timerCts.Cancel();
239-
}
240-
else
241-
{
242-
eventCts.Cancel();
243-
}
244-
245-
// This will either return the received value or throw if the task was cancelled.
246-
return await externalEventTask;
227+
return this.WaitForExternalEvent<T>(eventName, timeout, CancellationToken.None);
247228
}
248229

249230
/// <param name="eventName">

0 commit comments

Comments
 (0)