protected override async Task ExecuteAsync(CancellationToken stoppingToken) { IChangefeed <ThreadStats> threadStatsChangefeed = await _threadStatsChangefeedDbService.GetThreadStatsChangefeedAsync(stoppingToken); while (!stoppingToken.IsCancellationRequested && (await threadStatsChangefeed.MoveNextAsync(stoppingToken))) { string newThreadStats = threadStatsChangefeed.CurrentNewValue.ToString(); await Task.WhenAll( _serverSentEventsService.SendEventAsync(newThreadStats), _webSocketConnectionsService.SendToAllAsync(newThreadStats) ); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await _threadStatsChangefeedDbService.EnsureDatabaseCreatedAsync(); IChangefeed <ThreadStats> threadStatsChangefeed = await _threadStatsChangefeedDbService.GetThreadStatsChangefeedAsync(stoppingToken); try { await foreach (ThreadStats threadStatsChange in threadStatsChangefeed.FetchFeed(stoppingToken)) { string newThreadStats = threadStatsChange.ToString(); await Task.WhenAll( _serverSentEventsService.SendEventAsync(newThreadStats), _webSocketConnectionsService.SendToAllAsync(newThreadStats) ); } } catch (OperationCanceledException) { } }