Skip to content

Commit 5eba3ef

Browse files
committed
Fix Wait-DurableTask examples and output description
1 parent ce4c1a1 commit 5eba3ef

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/Help/Wait-DurableTask.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,39 @@ functions to coordinate multiple asynchronous operations and retrieve their resu
3131
```powershell
3232
$task1 = Invoke-DurableActivity -FunctionName "Step1" -Input "data1" -NoWait
3333
$task2 = Invoke-DurableActivity -FunctionName "Step2" -Input "data2" -NoWait
34-
$results = Wait-DurableTask -Task @($task1, $task2)
34+
$completedTasks = Wait-DurableTask -Task @($task1, $task2)
35+
36+
# Get the actual results from the completed tasks
37+
$results = @()
38+
foreach ($task in $completedTasks) {
39+
$results += Get-DurableTaskResult -Task $task
40+
}
3541
Write-Host "Both tasks completed with results: $results"
3642
```
3743

38-
This example demonstrates waiting for multiple durable activity tasks to complete and retrieving their results. The activities are invoked with -NoWait to return task objects immediately.
44+
This example demonstrates waiting for multiple durable activity tasks to complete. Note that Wait-DurableTask returns the task objects themselves, not the results. To get the actual activity results, you need to use Get-DurableTaskResult on each completed task.
3945

4046
### Example 2
4147

4248
```powershell
4349
$task1 = Invoke-DurableActivity -FunctionName "FastOperation" -Input $data1 -NoWait
4450
$task2 = Invoke-DurableActivity -FunctionName "SlowOperation" -Input $data2 -NoWait
45-
$firstResult = Wait-DurableTask -Task @($task1, $task2) -Any
46-
Write-Host "First task completed with result: $firstResult"
51+
$firstCompletedTask = Wait-DurableTask -Task @($task1, $task2) -Any
52+
53+
# Determine which task completed first and get its result
54+
if ($firstCompletedTask -eq $task1) {
55+
$activityResult = Get-DurableTaskResult -Task $firstCompletedTask
56+
Write-Host "FastOperation completed first with result: $activityResult"
57+
} elseif ($firstCompletedTask -eq $task2) {
58+
$activityResult = Get-DurableTaskResult -Task $firstCompletedTask
59+
Write-Host "SlowOperation completed first with result: $activityResult"
60+
} else {
61+
# This block should never be hit
62+
Write-Host "Unexpected task completion"
63+
}
4764
```
4865

49-
This example demonstrates waiting for any one of the tasks to complete using the -Any parameter. The cmdlet returns as soon as the first task finishes, which is useful for implementing timeout patterns or race conditions.
66+
This example demonstrates waiting for any one of the tasks to complete using the -Any parameter. The cmdlet returns the first completed task object (not the result), which you can then compare to determine which task finished first and retrieve its actual result using Get-DurableTaskResult.
5067

5168
## PARAMETERS
5269

@@ -112,15 +129,16 @@ This cmdlet does not accept pipeline input. All parameters must be specified dir
112129
113130
### System.Object
114131
115-
Returns the result(s) of the completed task(s). If waiting for a single task, returns the task result directly. If waiting for multiple tasks, returns an array of results in the same order as the input tasks.
132+
Returns the completed task object(s), not the task results. If waiting for a single task, returns the task object directly. If waiting for multiple tasks, returns an array of task objects in the same order as the input tasks. To get the actual results from the tasks, use Get-DurableTaskResult on the returned task objects.
116133
117134
## NOTES
118135
119136
- This cmdlet can only be used within orchestrator functions, not in activity functions or client functions.
120-
- When using the -Any parameter, only the result of the first completed task is returned. Other tasks continue running in the background.
137+
- When using the -Any parameter, only the first completed task object is returned. Other tasks continue running in the background.
121138
- Tasks passed to this cmdlet must be created with the -NoWait parameter from other durable cmdlets.
122139
- The cmdlet is fault-tolerant and will survive orchestration replays and restarts.
123-
- When waiting for multiple tasks without -Any, results are returned in the same order as the input tasks, regardless of completion order.
140+
- When waiting for multiple tasks without -Any, task objects are returned in the same order as the input tasks, regardless of completion order.
141+
- This cmdlet returns task objects, not task results. Use Get-DurableTaskResult to retrieve the actual results from completed tasks.
124142
- Use this cmdlet to implement common patterns like fan-out/fan-in, timeouts, and race conditions in orchestrations.
125143
126144
## RELATED LINKS

0 commit comments

Comments
 (0)