Skip to content

Instantly share code, notes, and snippets.

@andrewlock
Created September 14, 2016 08:47
Show Gist options
  • Save andrewlock/404fa531384a2a73418de59aeaa9ced2 to your computer and use it in GitHub Desktop.
Save andrewlock/404fa531384a2a73418de59aeaa9ced2 to your computer and use it in GitHub Desktop.
Getting a Task when you don't expect it
public class UserService
{
private readonly IUserRepo _repo;
public UserService(IUserRepo repo)
{
_repo = repo;
}
public async Task<bool> DoesUserExist(int userId)
{
//some async method, which is awaited, so no compiler warnings
var something = await _repo.SomeMethodAsync(userId);
// GetUser is an Async method returning a Task<User>
var user = _repo.GetUser(userId);
// Oops, this is always false
return user == null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment