protected virtual void Dispose(bool disposing)
 {
     if (!disposedValue)
     {
         if (disposing)
         {
             _workerErrorSubscription.Dispose();
             foreach (var subscription in _workerStateSubscriptions)
             {
                 subscription.Dispose();
             }
             foreach (var pair in _channelStates)
             {
                 // TODO #3296 - send WorkerTerminate message to shut down language worker process gracefully (instead of just a killing)
                 pair.Value.Channel.Dispose();
                 pair.Value.Functions.Dispose();
             }
             _server.ShutdownAsync().ContinueWith(t => t.Exception.Handle(e => true), TaskContinuationOptions.OnlyOnFaulted);
         }
         disposedValue = true;
     }
 }
        public async Task OuterStopAsync(CancellationToken cancellationToken)
        {
            _logger.LogDebug("Shutting down RPC server");

            try
            {
                Task shutDownRpcServer = _rpcServer.ShutdownAsync();
                Task shutdownResult    = await Task.WhenAny(shutDownRpcServer, Task.Delay(_rpcServerShutdownTimeoutInMilliseconds));

                if (!shutdownResult.Equals(shutDownRpcServer) || shutDownRpcServer.IsFaulted)
                {
                    _logger.LogDebug("Killing RPC server");
                    await _rpcServer.KillAsync();
                }
            }
            catch (AggregateException ae)
            {
                ae.Handle(e =>
                {
                    _logger.LogError(e, "Shutting down RPC server encountered exception: '{message}'", e.Message);
                    return(true);
                });
            }
        }
 public async Task OuterStopAsync(CancellationToken cancellationToken)
 {
     await rpcServer.ShutdownAsync();
 }