Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IPipeline {
- Task Start();
- Task Cycle();
- Task Stop();
- }
- ...
- protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
- log.LogInformation($"Starting subsystems");
- foreach(var engine in pipeLine) {
- try {
- await engine.Start();
- }
- catch(Exception ex) {
- log.LogError(ex, $"{nameof(engine)} failed to start");
- }
- }
- log.LogInformation($"Runnning main loop");
- while(!stoppingToken.IsCancellationRequested) {
- foreach(var engine in pipeLine) {
- try {
- await engine.Cycle();
- }
- catch(Exception ex) {
- log.LogError(ex, $"{engine.GetType().Name} error in Cycle");
- }
- }
- }
- log.LogInformation($"Stopping subsystems");
- foreach(var engine in pipeLine) {
- try {
- await engine.Stop();
- }
- catch(Exception ex) {
- log.LogError(ex, $"{nameof(engine)} failed to stop");
- }
- }
- }
- public async Task Cycle() {
- await Task.CompletedTask;
- }
- public async Task Cycle() {
- await Task.Delay(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement