@@ -35,7 +35,8 @@ namespace Discord.Net.Queue | |||||
private RestRequest(IRestClient client, string method, string endpoint, bool headerOnly, RequestOptions options) | private RestRequest(IRestClient client, string method, string endpoint, bool headerOnly, RequestOptions options) | ||||
{ | { | ||||
var timeout = options?.Timeout; | |||||
if (options == null) | |||||
options = RequestOptions.Default; | |||||
Client = client; | Client = client; | ||||
Method = method; | Method = method; | ||||
@@ -43,7 +44,7 @@ namespace Discord.Net.Queue | |||||
Json = null; | Json = null; | ||||
MultipartParams = null; | MultipartParams = null; | ||||
HeaderOnly = headerOnly; | 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>(); | 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, 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) | public WebSocketRequest(IWebSocketClient client, byte[] data, int index, int count, bool isText, RequestOptions options) | ||||
{ | { | ||||
if (options == null) | |||||
options = RequestOptions.Default; | |||||
Client = client; | Client = client; | ||||
Data = data; | Data = data; | ||||
DataIndex = index; | DataIndex = index; | ||||
DataCount = count; | DataCount = count; | ||||
IsText = isText; | 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>(); | Promise = new TaskCompletionSource<Stream>(); | ||||
} | } | ||||
@@ -2,7 +2,14 @@ | |||||
{ | { | ||||
public class RequestOptions | 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> | /// <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 int? Timeout { get; set; } | ||||
public RequestOptions() | |||||
{ | |||||
Timeout = 30000; | |||||
} | |||||
} | } | ||||
} | } |