private static void Deliver(Request request, Response response, Action action = null) { if (request.IsCanceled) { request.Finish("canceled-at-delivery"); return; } if (response.IsSuccess) { request.SetResponse(response); } else { request.SetError(response.Error); } if (response.IsIntermediate) { request.AddMarker("intermediate-response"); } else { request.Finish("done"); } if (action != null) { action(); } }
private static void AttemptRetry(Request request, RequestException exception) { var retry_policy = request.RetryPolicy; var timeout_ms = retry_policy.CurrentTimeoutMs; try { retry_policy.Retry(exception); request.AddMarker(String.Format("retry [timeout={0}]", timeout_ms)); } catch (RequestException) { request.AddMarker(String.Format("timeout-giveup [timeout={0}]", timeout_ms)); throw; } }
public void PostError(Request request, Error error) { request.AddMarker("post-error"); var response = new Response { Error = error }; _invoke(() => Deliver(request, response)); }
public void PostException(Request request, RequestException exception) { request.AddMarker("post-exception"); var response = new Response { Exception = exception }; Deliver(request, response); }
public Request Add(Request request) { lock (_requests) { _requests.Add(request); } request.RequestQueue = this; request.Sequence = Interlocked.Increment(ref _sequence); request.AddMarker("add-to-queue"); if (!request.ShouldCache) { _network_queue.Add(request); return(request); } lock (_blocked_requests) { List <Request> list; if (_blocked_requests.TryGetValue(request.CacheKey, out list)) { list = list ?? new List <Request>(); list.Add(request); _blocked_requests[request.CacheKey] = list; } else { _blocked_requests[request.CacheKey] = null; _cache_queue.Add(request); } } return(request); }
public Request Add(Request request) { lock (_requests) { _requests.Add(request); } request.RequestQueue = this; request.Sequence = Interlocked.Increment(ref _sequence); request.AddMarker("add-to-queue"); if (!request.ShouldCache) { _network_queue.Add(request); return request; } lock (_blocked_requests) { List<Request> list; if (_blocked_requests.TryGetValue(request.CacheKey, out list)) { list = list ?? new List<Request>(); list.Add(request); _blocked_requests[request.CacheKey] = list; } else { _blocked_requests[request.CacheKey] = null; _cache_queue.Add(request); } } return request; }
public void PostResponse(Request request, Response response, Action action = null) { request.AddMarker("post-response"); _invoke(() => Deliver(request, response, action)); }
private static void AttemptRetry(Request request, Error error) { var retry_policy = request.RetryPolicy; var timeout_ms = retry_policy.CurrentTimeoutMs; try { retry_policy.Retry(error); request.AddMarker(String.Format("retry [timeout={0}]", timeout_ms)); } catch (Error) { request.AddMarker(String.Format("timeout-giveup [timeout={0}]", timeout_ms)); throw; } }