Created
July 31, 2014 16:00
-
-
Save Rast1234/b5a9f24668102d9fa05f to your computer and use it in GitHub Desktop.
Mix callbacks and async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For example, given the following method: | |
public void GetStringFromUrl(string url, Action<string> onCompleted); | |
//The only way I know of to wrap this into a method returning a task is: | |
public Task<string> GetStringFromUrl(string url) | |
{ | |
var t = new TaskCompletionSource<string>(); | |
GetStringFromUrl(url, s => t.TrySetResult(s)); | |
return t.Task; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment