How would one go about waiting for an asynchronous result in a controller method? It seems like it would be trivial to implement, but so far I have not found a good example that is clean and elegant.
Here is the problem. I have two controller methods. Method A and Method B. Method A starts a long running process via TaskFactory, and uses ContinueWith to update a cached value when the process is finished. There are some intermediate steps between A and B. Now when I get to Method B, I need to check the value in the cache. If the value in the cache has not been updated yet, I need to wait for x amount of seconds and periodically check to see if the value has been updated.
I would prefer to handle all of this in the controller, so the client doesn’t have to poll for the result (and having to rewrite the controller to handle the polling). But I haven’t been able to figure out a way to implement the polling inside the controller method that doesn’t block until the timeout expires(I’m worried about thread pool starvation). Maybe there isn’t a clean implementation that I can use here. And if polling is the right or only answer, I will just have to accept it.
HTTP is a stateless protocol. You can’t implement such polling on the server without blocking. You have 2 possibilities: