restsharp/RestSharp — pull request #367 by ErikSchierboom (2013-03-30 16:22:15+00:00)
Title: Added ExecuteAsync overloads that return Task<T>. fixes #366

The `ExecuteAsync` method is very useful, but does not integrate well with the [Task Parallel Library](http://msdn.microsoft.com/en-us/library/dd460717.aspx) which works with `Task` instances. C# 5.0's async/await functionality also depends on `Task` instances. Thus, I would love to see overloads of the ExecuteAsync method that return `Task` instances.

In this pull request I have added two methods to RestClient.Async.cs:
* `Task ExecuteAsync(IRestRequest request, CancellationToken token)`
* `Task ExecuteAsync(IRestRequest request, CancellationToken token)`

Internally, these methods call the existing ExecuteAsync method, which is simply wrapped in a `TaskCompletionSource` instance which allows the method to return a type of `Task`. Using a `TaskCompletionSource` instance also allows us to use a `CancellationToken`, which is the default way in which TPL tasks can be cancelled (the cancellation internally uses the `Abort` method of the `RestRequestAsyncHandle` class.

Unfortunately, only .NET framework 4 and higher contain the `Task` class. I thus had to add a conditional compilation symbol to have it compile on all platforms. For this, I used `#if NET4`, which is how this is also done elsewhere in the library.

Hopefully you will consider this a valid contribution.