private async Task <IChannelHost> CreateChannelAsync(ulong channelId, bool ackable) { IChannelHost chanHost; IConnectionHost connHost = null; while (true) { _logger.LogTrace(LogMessages.ChannelPools.CreateChannel, channelId); var sleep = false; // Get ConnectionHost try { connHost = await _connectionPool.GetConnectionAsync().ConfigureAwait(false); } catch { _logger.LogTrace(LogMessages.ChannelPools.CreateChannelFailedConnection, channelId); sleep = true; } // Create a Channel Host if (!sleep) { try { chanHost = new ChannelHost(channelId, connHost, ackable); await _connectionPool.ReturnConnectionAsync(connHost); // Return Connection (or lose them.) _flaggedChannels[chanHost.ChannelId] = false; _logger.LogDebug(LogMessages.ChannelPools.CreateChannelSuccess, channelId); return(chanHost); } catch { _logger.LogTrace(LogMessages.ChannelPools.CreateChannelFailedConstruction, channelId); sleep = true; } } // Sleep on failure. if (sleep) { if (connHost != null) { await _connectionPool.ReturnConnectionAsync(connHost); } // Return Connection (or lose them.) _logger.LogDebug(LogMessages.ChannelPools.CreateChannelSleep, channelId); await Task .Delay(Options.PoolOptions.SleepOnErrorInterval) .ConfigureAwait(false); } } }
private async Task <IChannelHost> CreateChannelAsync(ulong channelId, bool ackable) { IChannelHost chanHost = null; IConnectionHost connHost = null; while (true) { _logger.LogTrace(LogMessages.ChannelPools.CreateChannel, channelId); // Get ConnectionHost try { connHost = await _connectionPool.GetConnectionAsync().ConfigureAwait(false); } catch { _logger.LogTrace(LogMessages.ChannelPools.CreateChannelFailedConnection, channelId); await ReturnConnectionWithOptionalSleep(connHost, channelId, Options.PoolOptions.SleepOnErrorInterval).ConfigureAwait(false); continue; } // Create a Channel Host try { chanHost = new ChannelHost(channelId, connHost, ackable); await ReturnConnectionWithOptionalSleep(connHost, channelId, 0).ConfigureAwait(false); _flaggedChannels[chanHost.ChannelId] = false; _logger.LogDebug(LogMessages.ChannelPools.CreateChannelSuccess, channelId); return(chanHost); } catch { _logger.LogTrace(LogMessages.ChannelPools.CreateChannelFailedConstruction, channelId); await ReturnConnectionWithOptionalSleep(connHost, channelId, Options.PoolOptions.SleepOnErrorInterval).ConfigureAwait(false); } } }