Added default request timeout
This commit is contained in:
@@ -35,7 +35,8 @@ namespace Discord.Net.Queue
|
||||
|
||||
private RestRequest(IRestClient client, string method, string endpoint, bool headerOnly, RequestOptions options)
|
||||
{
|
||||
var timeout = options?.Timeout;
|
||||
if (options == null)
|
||||
options = RequestOptions.Default;
|
||||
|
||||
Client = client;
|
||||
Method = method;
|
||||
@@ -43,7 +44,7 @@ namespace Discord.Net.Queue
|
||||
Json = null;
|
||||
MultipartParams = null;
|
||||
HeaderOnly = headerOnly;
|
||||
TimeoutTick = timeout.HasValue ? (int?)unchecked(Environment.TickCount + timeout.Value) : null;
|
||||
TimeoutTick = options.Timeout.HasValue ? (int?)unchecked(Environment.TickCount + options.Timeout.Value) : null;
|
||||
Promise = new TaskCompletionSource<Stream>();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,15 +20,15 @@ namespace Discord.Net.Queue
|
||||
public WebSocketRequest(IWebSocketClient client, byte[] data, bool isText, RequestOptions options) : this(client, data, 0, data.Length, isText, options) { }
|
||||
public WebSocketRequest(IWebSocketClient client, byte[] data, int index, int count, bool isText, RequestOptions options)
|
||||
{
|
||||
if (options == null)
|
||||
options = RequestOptions.Default;
|
||||
|
||||
Client = client;
|
||||
Data = data;
|
||||
DataIndex = index;
|
||||
DataCount = count;
|
||||
IsText = isText;
|
||||
if (options != null)
|
||||
TimeoutTick = unchecked(Environment.TickCount + options.Timeout.Value);
|
||||
else
|
||||
TimeoutTick = null;
|
||||
TimeoutTick = options.Timeout.HasValue ? (int?)unchecked(Environment.TickCount + options.Timeout.Value) : null;
|
||||
Promise = new TaskCompletionSource<Stream>();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,14 @@
|
||||
{
|
||||
public class RequestOptions
|
||||
{
|
||||
public static RequestOptions Default => new RequestOptions();
|
||||
|
||||
/// <summary> The max time, in milliseconds, to wait for this request to complete. If null, a request will not time out. If a rate limit has been triggered for this request's bucket and will not be unpaused in time, this request will fail immediately. </summary>
|
||||
public int? Timeout { get; set; }
|
||||
|
||||
public RequestOptions()
|
||||
{
|
||||
Timeout = 30000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user