Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public interface IPipeline {
  2. Task Start();
  3. Task Cycle();
  4. Task Stop();
  5. }
  6.  
  7. ...
  8.  
  9. protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
  10. log.LogInformation($"Starting subsystems");
  11.  
  12. foreach(var engine in pipeLine) {
  13. try {
  14. await engine.Start();
  15. }
  16. catch(Exception ex) {
  17. log.LogError(ex, $"{nameof(engine)} failed to start");
  18. }
  19. }
  20.  
  21. log.LogInformation($"Runnning main loop");
  22.  
  23. while(!stoppingToken.IsCancellationRequested) {
  24. foreach(var engine in pipeLine) {
  25. try {
  26. await engine.Cycle();
  27. }
  28. catch(Exception ex) {
  29. log.LogError(ex, $"{engine.GetType().Name} error in Cycle");
  30. }
  31. }
  32. }
  33.  
  34. log.LogInformation($"Stopping subsystems");
  35.  
  36. foreach(var engine in pipeLine) {
  37. try {
  38. await engine.Stop();
  39. }
  40. catch(Exception ex) {
  41. log.LogError(ex, $"{nameof(engine)} failed to stop");
  42. }
  43. }
  44. }
  45.  
  46. public async Task Cycle() {
  47. await Task.CompletedTask;
  48. }
  49.  
  50. public async Task Cycle() {
  51. await Task.Delay(1);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement