File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . Net . Http ;
3+ using System . Threading ;
34using System . Threading . Tasks ;
45using ArcadeDotnet . Core ;
56using ArcadeDotnet . Exceptions ;
@@ -28,6 +29,12 @@ public Uri BaseUrl
2829 init { this . _options . BaseUrl = value ; }
2930 }
3031
32+ public TimeSpan Timeout
33+ {
34+ get { return this . _options . Timeout ; }
35+ init { this . _options . Timeout = value ; }
36+ }
37+
3138 public string APIKey
3239 {
3340 get { return this . _options . APIKey ; }
@@ -78,11 +85,16 @@ public async Task<HttpResponse> Execute<T>(HttpRequest<T> request)
7885 Content = request . Params . BodyContent ( ) ,
7986 } ;
8087 request . Params . AddHeadersToRequest ( requestMessage , this ) ;
88+ using CancellationTokenSource cts = new ( this . Timeout ) ;
8189 HttpResponseMessage responseMessage ;
8290 try
8391 {
8492 responseMessage = await this
85- . HttpClient . SendAsync ( requestMessage , HttpCompletionOption . ResponseHeadersRead )
93+ . HttpClient . SendAsync (
94+ requestMessage ,
95+ HttpCompletionOption . ResponseHeadersRead ,
96+ cts . Token
97+ )
8698 . ConfigureAwait ( false ) ;
8799 }
88100 catch ( HttpRequestException e1 )
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ public Uri BaseUrl
1717 set { _baseUrl = new ( ( ) => value ) ; }
1818 }
1919
20+ public TimeSpan Timeout { get ; set ; } = TimeSpan . FromMinutes ( 1 ) ;
21+
2022 /// <summary>
2123 /// API key used for authorization in header
2224 /// </summary>
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ public interface IArcadeClient
1717
1818 Uri BaseUrl { get ; init ; }
1919
20+ TimeSpan Timeout { get ; init ; }
21+
2022 /// <summary>
2123 /// API key used for authorization in header
2224 /// </summary>
You can’t perform that action at this time.
0 commit comments