ringcentral / RingCentral.Net

RingCentral SDK for .NET
MIT License
19 stars 26 forks source link

Add support for CancellationTokens #18

Closed BryceBarbara closed 4 years ago

BryceBarbara commented 4 years ago

Without support for CancellationTokens, we're unable to stop pending requests or properly implement timeouts without resorting to either killing threads or orphaning tasks.

After doing a quick poke around, it looks like initial support could be added by allowing for the passing of an optional CancellationToken to the SendAsync call at RestClient.cs:55 and then updating all the functions that call into this Request() function.

tylerlong commented 4 years ago

The underlying HTTP library is System.Net.Http, could you please show me some sample code using System.Net.Http? Not sure how to do it. Thanks.

Update: Never mind, I've found it: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.sendasync

tylerlong commented 4 years ago

Supported in 4.0.0-beta2

Usage sample: https://github.com/ringcentral/RingCentral.Net/blob/master/RingCentral.Tests/CancellationTest.cs

BryceBarbara commented 4 years ago

Great work Tyler! Thanks for the quick turn-around on this. It's something that definitely makes the SDK feel a bit more ready for prime-time usage!