Add WaitForExternalEvent overload with timeout and cancellation token #555
+135
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The isolated worker lacks a
WaitForExternalEventoverload accepting bothTimeSpan timeoutandCancellationToken, preventing users from implementing race scenarios where:Changes
Added overload
Task<T> WaitForExternalEvent<T>(string eventName, TimeSpan timeout, CancellationToken cancellationToken)Task.WhenAnyRefactored existing timeout-only overload to delegate to new overload with
CancellationToken.NoneAdded integration tests covering event-wins, cancellation-wins, and timeout-wins scenarios
Usage
Matches the in-process mode API signature users expect.
Original prompt
This section details on the original issue you should resolve
<issue_title>WaitForExternalEvent(eventName, timespan, cancellationToken) not supported (anymore?) in isolated mode</issue_title>
<issue_description>Hi there,
Context / issue
We came across an API change in the
WaitForExternalEvent<T>in theMicrosoft.DurableTaskpackage as we had the code below in place for in-process, wait for external events for 7 days, or when the cancellationtoken has ben cancelled when the winner prevails:Now, in isolated mode, we don't have the option to cancel the token externally, and are forced to use a timer to achieve the 'same' functionality as we had in the in-process mode. The only options we have are:

Expected result
To be able to pass in the cancellationtoken next to the timespan as we could in the in-process variant, to cancel the other tasks when one task prevails as winner.
Below some code snippets to demonstrate the issue I try to describe here. Feel free to inform me to clarify or elaborate on certain parts.
Regards,
Tom
Not working:
Not working with timespan and timertask either
Working with timertask: