DurableFunction generating n tasks inside function #1967
-
Hello, I have a question related to how the best way is to do the following: Today, this function that is processing those files are opening one thread for each file and, once all finishes, I'm merging their results. With that, if I receive a zip with 1k files, I will start 1k tasks. Below, one example: var tasks = new List<Task<ObjectX>>();
foreach (string path in paths)
{
tasks.Add(Task.Factory.StartNew(() => someProcessing));
}
await Task.WhenAll(tasks); Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You would essentially just put your The code would look almost exactly the same, but you would replace This is a very common pattern that we call fan-out/fan-in. |
Beta Was this translation helpful? Give feedback.
You would essentially just put your
someProcessing
as an Activity Function. These activity functions could then be executed in parallel across the various VMs your function application is scaled out to. In addition, the need to repeat this processing work if your function crashes becomes more minimal because the results of each step will be stored persistently.The code would look almost exactly the same, but you would replace
Task.Factory.StartNew(() => someProcessing)
withcontext.CallActivityAsync(nameof(SomeProcessingActivity), path)
.This is a very common pattern that we call fan-out/fan-in.