Reputation: 2731
I'm planning to move some ASP.NET code that performs several I/O operations in parallel. The existing code creates a Task for each operation and then uses Task.WaitAll to wait for these to finish before moving to the next steps.
In Orleans I'm planning on separate grains for each of these I/O operations and a coordinating grain that calls them.
Is the use of background Tasks and WaitAll the preferred method for parallel processing in Orleans as well?
If there are any Orleans specific patterns or recommendations I'd like to try those first. I'm still reviewing the docs and may find the answer there. Any insights or references to the appropriate documentation will be very helpful.
Upvotes: 2
Views: 163
Reputation: 5808
It's not clear why you want to dispatch asynchronous IO work out of the grain. Since it's asynchronous (i.e. doesn't block grain's thread) you can do something like this:
public class JustAGrain : Grain, IJustAGrain
{
...
public async Task<string> DoManyAsync()
{
var httpClient = new HttpClient();
var t1 = httpClient.GetAsync("https://dummy.restapiexample.com/api/v1/employee/1");
var t2 = httpClient.GetAsync("https://dummy.restapiexample.com/api/v1/employee/1");
var t3 = httpClient.GetAsync("https://dummy.restapiexample.com/api/v1/employee/1");
await Task.WhenAll(t1, t2, t3);
return $"{t1.Result.StatusCode} {t2.Result.StatusCode} {t3.Result.StatusCode}";
}
...
}
Upvotes: 3