Hello, I've encountered an issue with the code in my controller:
[HttpGet]
[Route("/Test")]
public async Task<IActionResult> Test() {
Console.WriteLine("foo");
await Task.Delay(2000);
Console.WriteLine("bar");
return Ok();
}
I attempted to test it using JavaScript:
for(let i=0; i<2; i++){
axios.get('/Test').then(response => {
console.log(`task ${i} finish`)
})
}
The expected server output should be:
foo
foo
foo
bar
bar
bar
However, what I actually received was:
foo
bar
foo
bar
foo
bar
I'm confused as to why await Task.Delay(2000)
did not allow the control flow to handle other requests concurrently. It seems like the action method is not capable of handling a large number of requests simultaneously. Am I misunderstanding something about async/await? What changes should I make if I want to simulate a non-blocking lengthy web service call?
I've read this post but still can't find a solution