I'am new to Blazor wasm. Actually I have HttpClient added as singleton to the services in program.cs. Then I use a generic utility class (HttpService) where HttpClient is injected to do http calls (GetAsync, PostAsync,...). Everywhere I use async await pattern. First case: in some page I should do simultaneous get webapi calls and then when all are done do some calculations on results. Second case: in other page I have the opposed need, do a call, wait for result and then use it for a second call.
I try and I notice that my code with calls like:
HttpService:
public async Task<dataDTO> GetData(int id)
{
var httpResponse = await httpService.Get<DataDTO>($"{baseURL}/{id}");
if (!httpResponse.Success)
{
var msg = await httpResponse.GetBody();
throw new ApplicationException(msg);
}
return httpResponse.Response;
}
And calls in page component:
var result1 = await GetData(5000);
var result2 = await GetData(2000);
var result3 = await GetData(500);
Suppose that the parameter are milliseconds that server use to delay the response. These calls are always syncronous. The next wait the end of previous to be executed. (second case).
How to implement the first case (simultaneous calls)?
Thank you very much.
Task.WhenAllorTask.WaitAllsome request can be lost.