protected virtual void CleanPendingRequests(object sender, ElapsedEventArgs args) { var now = CurrentTime; var requestsToCancel = PendingRequestStore.FindAllToCancel(now); foreach (var requestState in requestsToCancel) { // request is either cancelled (via CancellationToken) or expired var canceled = requestState.CancellationToken.IsCancellationRequested ? requestState.TaskCompletionSource.TrySetCanceled(requestState.CancellationToken) : requestState.TaskCompletionSource.TrySetCanceled(); if (PendingRequestStore.Remove(requestState.Id) && canceled) { Log.DebugFormat("Pending request timed-out: {0}, now: {1}", requestState, now); // ToDo: add and API hook to these kind of situation } } }
/// <summary> /// Performs cleanup of pending requests (requests that timed out or were cancelled). /// </summary> public virtual void CleanPendingRequests() { var now = CurrentTime; var requestsToCancel = PendingRequestStore.FindAllToCancel(now); foreach (var requestState in requestsToCancel) { // request is either cancelled (via CancellationToken) or expired var canceled = requestState.CancellationToken.IsCancellationRequested ? requestState.TaskCompletionSource.TrySetCanceled(requestState.CancellationToken) : requestState.TaskCompletionSource.TrySetCanceled(); if (PendingRequestStore.Remove(requestState.Id) && canceled) { Log.DebugFormat("Pending request timed-out: {0}, now: {1}", requestState, now); // Execute the event hook // ToDo: sort out the ConsumerSettings arg for req/resp, for now pass null (Settings.RequestResponse.OnMessageExpired ?? Settings.OnMessageExpired)?.Invoke(null, requestState.Request); } } }