using the 2.0 driver the following code will sometimes hang and never return.
public async Task GetFirst(FilterDefinition query)
{
retu
There are 2 solutions:
Add a ConfigureAwait(false)
at the end:
return await GetCollection.Find(query).FirstOrDefaultAsync().ConfigureAwait(false);
Just return the Task<T>
, since the result of FirstOrDefaultAsync()
is the same type as the result you want to return.
public Task<T> GetFirst(FilterDefinition<T> query)
{
return GetCollection.Find(query).FirstOrDefaultAsync();
}