public async Task SendAsync(WebSocketRequest request) { int id = Interlocked.Increment(ref nextId); #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Start"); #endif LastAttemptAt = DateTimeOffset.UtcNow; while (true) { await _queue.EnterGlobalAsync(id, request).ConfigureAwait(false); await EnterAsync(id, request).ConfigureAwait(false); #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Sending..."); #endif try { await request.SendAsync().ConfigureAwait(false); return; } catch (TimeoutException) { #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Timeout"); #endif if ((request.Options.RetryMode & RetryMode.RetryTimeouts) == 0) { throw; } await Task.Delay(500).ConfigureAwait(false); continue; //Retry } /*catch (Exception) * { #if DEBUG_LIMITS * Debug.WriteLine($"[{id}] Error"); #endif * if ((request.Options.RetryMode & RetryMode.RetryErrors) == 0) * throw; * * await Task.Delay(500); * continue; //Retry * }*/ finally { UpdateRateLimit(id, request, default(RateLimitInfo), false); #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Stop"); #endif } } }
public async Task SendAsync(WebSocketRequest request) { //TODO: Re-impl websocket buckets request.CancelToken = _requestCancelToken; await request.SendAsync().ConfigureAwait(false); }