public async Task <TResponse> SendWithRetry <TResponse>(ISession session, IReliableRequest request) where TResponse : class, IResponse { if (request.RequestId == 0) { request.RequestId = request.RequestId = session.GetNextRequestId(); } var responseWaiter = _messageSource.WaitForResponse(request.RequestId); await Task.WhenAny(SendWithRetry(session, request), responseWaiter); var response = (TResponse)await responseWaiter; Acknowledge(request.RequestId, true); return(response); }