Skip to content

Commit aed874b

Browse files
Supplementing .NET Workflows fan in/out pattern documentation (#4716)
* Supplemented to reflect an extension method introduced with 1.16 in the .NET SDK to simplify processing work in parallel but with an upper concurrency cap. Signed-off-by: Whit Waldo <[email protected]> * Fixed mismatched variable name Signed-off-by: Whit Waldo <[email protected]> --------- Signed-off-by: Whit Waldo <[email protected]> Co-authored-by: Marc Duiker <[email protected]>
1 parent add226c commit aed874b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,29 @@ await context.CallActivityAsync("PostResults", sum);
624624
625625
{{< /tabs >}}
626626
627+
With the release of 1.16, it's even easier to process workflow activities in parallel while putting an upper cap on
628+
concurrency by using the following extension methods on the `WorkflowContext`:
629+
630+
{{< tabs ".NET" >}}
631+
632+
{{% codetab %}}
633+
<!-- .NET -->
634+
```csharp
635+
//Revisiting the earlier example...
636+
// Get a list of work items to process
637+
var workBatch = await context.CallActivityAsync<object[]>("GetWorkBatch", null);
638+
639+
// Process deterministically in parallel with an upper cap of 5 activities at a time
640+
var results = await context.ProcessInParallelAsync(workBatch, workItem => context.CallActivityAsync<int>("ProcessWorkItem", workItem), maxConcurrency: 5);
641+
642+
var sum = results.Sum(t => t);
643+
await context.CallActivityAsync("PostResults", sum);
644+
```
645+
646+
{{% /codetab %}}
647+
648+
{{< /tabs >}}
649+
627650
Limiting the degree of concurrency in this way can be useful for limiting contention against shared resources. For example, if the activities need to call into external resources that have their own concurrency limits, like a databases or external APIs, it can be useful to ensure that no more than a specified number of activities call that resource concurrently.
628651
629652
## Async HTTP APIs

0 commit comments

Comments
 (0)