Created
April 30, 2014 18:23
-
-
Save jrusbatch/a577fda6d64eda821172 to your computer and use it in GitHub Desktop.
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
public static Task<BrokeredMessage> OnMessageAsyncWrapper(CancellationToken cancellationToken = default(CancellationToken)) | |
{ | |
var tcs = new TaskCompletionSource<BrokeredMessage>(); | |
try | |
{ | |
if (cancellationToken.IsCancellationRequested) | |
{ | |
tcs.SetCanceled(); | |
return tcs.Task; | |
} | |
OnMessageAsync(msg => | |
{ | |
tcs.TrySetResult(msg); | |
return tcs.Task; | |
}); | |
} | |
catch (Exception ex) | |
{ | |
tcs.TrySetException(ex); | |
} | |
return tcs.Task; | |
} | |
public static void OnMessageAsync(Func<BrokeredMessage, Task> callback) | |
{ | |
callback(default(BrokeredMessage)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment