Exemple #1
0
        public void Close()
        {
            if (_closed)
            {
                return;
            }

            _logger.LogDebug("Close() | Channel");

            _closed = true;

            // Close every pending sent.
            try
            {
                _sents.Values.ForEach(m => m.Close.Invoke());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Close() | _sents.Values.ForEach(m => m.Close.Invoke())");
            }

            // Remove event listeners but leave a fake 'error' hander to avoid
            // propagation.
            _consumerSocket.Closed -= ConsumerSocketOnClosed;
            _consumerSocket.Error  -= ConsumerSocketOnError;

            _producerSocket.Closed -= ProducerSocketOnClosed;
            _producerSocket.Error  -= ProducerSocketOnError;

            // Destroy the socket after a while to allow pending incoming messages.
            // 在 Node.js 实现中,延迟了 200 ms。
            try
            {
                _producerSocket.Close();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Close() | _producerSocket.Close()");
            }

            try
            {
                _consumerSocket.Close();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Close() | _consumerSocket.Close()");
            }
        }
Exemple #2
0
        public void Close()
        {
            if (_closed)
            {
                return;
            }

            _logger.LogDebug("Close()");

            _closed = true;

            // Remove event listeners but leave a fake 'error' hander to avoid
            // propagation.
            _consumerSocket.Closed -= ConsumerSocketOnClosed;
            _consumerSocket.Error  -= ConsumerSocketOnError;

            _producerSocket.Closed -= ProducerSocketOnClosed;
            _producerSocket.Error  -= ProducerSocketOnError;

            // Destroy the socket after a while to allow pending incoming messages.
            // 在 Node.js 实现中,延迟了 200 ms。
            try
            {
                _producerSocket.Close();
            }
            catch (Exception)
            {
            }

            try
            {
                _consumerSocket.Close();
            }
            catch (Exception)
            {
            }
        }