private async Task CreateNodeInstances(NodeServicesOptions options)
 {
     for (int i = 0; i < _services.Length; ++i)
     {
         _services[i] = new HotNodeService(CreateNodeInstance(options));
         await WarmupService(_services[i], CancellationToken.None);
     }
 }
        private async Task ReloadService(int serviceIndex, CancellationToken token)
        {
            _logger.LogInformation($"Reloading NodeService [{serviceIndex}]");
            try {
                var oldService = _services[serviceIndex];

                if (_options.NodeServicesOptions.LaunchWithDebugging)
                {
                    oldService.Dispose();
                }
                var newService = new HotNodeService(CreateNodeInstance(_options.NodeServicesOptions));
                await WarmupService(newService, token);

                if (_options.HotModuleReplacement && serviceIndex == _services.Length - 1)
                {
                    if (DirectLinkHub.HubContext != null)
                    {
                        await DirectLinkHub.HubContext.Clients.All.SendAsync(nameof(IDirectLinkHub.AssetsUpdate), new object[] { });
                    }
                }
                if (!_options.NodeServicesOptions.LaunchWithDebugging)
                {
#pragma warning disable 4014
                    Task.Run(async() => {
                        await Task.Delay(_options.NodeServiceDisposingDelay, token);
                        oldService.Dispose();
                    }, token);
#pragma warning restore 4014
                }

                _services[serviceIndex] = newService;
            }
            catch (AggregateException ae) {
                ae.Handle(ex => ex is TaskCanceledException);
            }
            catch (Exception ex) {
                _logger.LogError(0, ex, $"Reloading NodeService [{serviceIndex}] threw an exception");
            }
        }