I think I have a general misunderstanding of the way the async/await pair works. I'm using an EasyNetQ method (an interface for RabbitMQ in C#) and I'm trying to call the following method I created:
public Task<U> RequestDirectReply<T, U>(T request, int timeout) where T : class where U : class
{
using (var bus = RabbitHutch.CreateBus($"virtualHost=MyVirtualHost;timeout={timeout};host=MyHostName"))
{
return bus.RequestAsync<T, U>(request);
}
}
Now the way that I understand this, I should be able to call this method, get a Task from RequestAsync, then do a bunch of stuff and then await that Task once I'm done with that stuff. Something like this:
Task<Reply> task = RequestDirectReply<Request, Reply>(msg, 10);
for (int i = 0; i < 1000000000; ++i)
{
// Hi, I'm counting to a billion
}
var reply = await task;
However, the program blocks on the call to RequestAsync for the timeout duration rather than on the await. Then the await immediately throws a timeout exception.
To see if I was misunderstanding, I tried the following as well:
public async Task<U> RequestDirectReply<T, U>(T request, int timeout) where T : class where U : class
{
using (var bus = RabbitHutch.CreateBus($"virtualHost=MyVirtualHost;timeout={timeout};host=MyHostName"))
{
return await bus.RequestAsync<T, U>(request);
}
}
Same thing. It blocks on the RequestAsync. How is that different than a regular blocking synchronous call?