Esempio n. 1
0
        public void Close()
        {
            if (Closed)
            {
                return;
            }
            Closed = true;

            // Kill the worker process.
            if (_child != null)
            {
                // Remove event listeners but leave a fake 'error' hander to avoid
                // propagation.
                _child.Kill(15 /*SIGTERM*/);
                _child = null;
            }

            // Close the Channel instance.
            _channel?.Close();

            // Close the PayloadChannel instance.
            _payloadChannel?.Close();

            // Emit observer event.
            Observer.Emit("close");
        }
Esempio n. 2
0
        public async Task CloseAsync()
        {
            if (_closed)
            {
                return;
            }

            await _closeLock.WaitAsync();

            try
            {
                if (_closed)
                {
                    return;
                }

                _logger.LogDebug("CloseAsync() | Worker");

                _closed = true;

                // Kill the worker process.
                if (_child != null)
                {
                    // Remove event listeners but leave a fake 'error' hander to avoid
                    // propagation.
                    _child.Kill(15 /*SIGTERM*/);
                    _child = null;
                }

                // Close the Channel instance.
                _channel?.Close();

                // Close the PayloadChannel instance.
                _payloadChannel?.Close();

                // Close every Router.
                foreach (var router in _routers)
                {
                    await router.WorkerClosedAsync();
                }
                _routers.Clear();

                // Emit observer event.
                Observer.Emit("close");
            }
            finally
            {
                _closeLock.Set();
            }
        }