Skip to content

Instantly share code, notes, and snippets.

@mikeminutillo
Created February 20, 2012 06:15
Show Gist options
  • Save mikeminutillo/1868095 to your computer and use it in GitHub Desktop.
Save mikeminutillo/1868095 to your computer and use it in GitHub Desktop.
Extnesion method for Rx-ification
public static class Async
{
public static Func<Task<T>> Make<T>(Action<TaskCompletionSource<T>> action)
{
var completionSource = new TaskCompletionSource<T>();
action(completionSource);
return completionSource.Task;
}
}
public async Task<User> GetUser()
{
var _client = new GitHubClient
{
Authenticator = new HttpBasicAuthenticator("user", "pass")
};
var f = Async.Make<User>(cs => _client.Users.GetAuthenticatedUserAsync(cs.SetResult, _exceptionAction));
var result = await f.Invoke();
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment