Hello I have this code on my controller:
[HttpGet]
[Route("/Test")]
public async Task<IActionResult> Test() {
Console.WriteLine("foo");
await Task.Delay(2000);
Console.WriteLine("bar");
return Ok();
}
And try to test by javascript:
for(let i=0; i<2; i++){
axios.get('/Test').then(response => {
console.log(`task ${i} finish`)
})
}
I expect the output on server should be:
foo
foo
foo
bar
bar
bar
However what I got is:
foo
bar
foo
bar
foo
bar
I get confused that didn't await Task.Delay(2000)
will return the control flow back to process and able to handle other request meanwhile? It seems to me that the action method is not capable to handle large number of requests concurrently. Am I misunderstand something about async/await? What should I implement if I want to simulate a non-blocking lengthy web service call?
I read this post but still can't figure out what is the solution