I'm playing with async methods in an ApiController, and the behaviour surprises me. I invoke the following method:
// GET api/values/{id}
public async Task<object> Get(int id)
{
var received = DateTime.Now;
await Task.Delay(10000);
var finished = DateTime.Now;
return new { id, received, finished };
}
from four browser windows with the following URLs in order, with about a one second delay between each:
http://localhost:55571/api/values/1
http://localhost:55571/api/values/2
http://localhost:55571/api/values/3
http://localhost:55571/api/values/2
The first URL comes back, as expected, ten seconds after I launch it, followed shortly thereafter by the second and third URLs. However, the fourth URL, which is identical to the second URL, returns ten seconds after the second URL returns.
This suggests to me that something between the browser and my code is serialising requests either to the same URL, or the same set of parameters, or something else (and what about POST, PUT, etc.?). Rather than reverse-engineering this, I'd like to ask...
Is this behaviour documented somewhere?
EDIT: I tried clutching at this straw, to no avail.
EDIT: As requested in a comment, the timings are (roughly) as follows:
0 s: GET …/values/1
1 s: GET …/values/2
2 s: GET …/values/3
3 s: GET …/values/2 (2nd instance)
10 s: GOT …/values/1
11 s: GOT …/values/2
12 s: GOT …/values/3
21 s: GOT …/values/2 (2nd instance)