11using System . Diagnostics ;
2- using Initialization . Microsoft . Extensions . DependencyInjection ;
32using Microsoft . Extensions . Logging ;
43using ModularPipelines . Helpers ;
54
65namespace ModularPipelines . Engine . Executors ;
76
87[ StackTraceHidden ]
9- internal class PrintProgressExecutor : IPrintProgressExecutor , IInitializer
8+ internal class PrintProgressExecutor : IPrintProgressExecutor
109{
1110 private readonly EngineCancellationToken _engineCancellationToken ;
1211 private readonly IConsolePrinter _consolePrinter ;
1312 private readonly IModuleRetriever _moduleRetriever ;
1413 private readonly ILogger < PrintProgressExecutor > _logger ;
1514
16- private Task _printProgressTask = null ! ; // LateInit
17- private CancellationTokenSource _printProgressCancellationTokenSource = null ! ; // LateInit
15+ private Task ? _printProgressTask ;
16+ private CancellationTokenSource ? _printProgressCancellationTokenSource ;
1817
1918 public PrintProgressExecutor ( EngineCancellationToken engineCancellationToken ,
2019 IConsolePrinter consolePrinter ,
@@ -26,10 +25,8 @@ public PrintProgressExecutor(EngineCancellationToken engineCancellationToken,
2625 _moduleRetriever = moduleRetriever ;
2726 _logger = logger ;
2827 }
29-
30- public int Order => int . MaxValue ;
31-
32- public async Task InitializeAsync ( )
28+
29+ public async Task < IPrintProgressExecutor > InitializeAsync ( )
3330 {
3431 _printProgressCancellationTokenSource =
3532 CancellationTokenSource . CreateLinkedTokenSource ( _engineCancellationToken . Token ) ;
@@ -38,11 +35,13 @@ public async Task InitializeAsync()
3835
3936 _printProgressTask =
4037 _consolePrinter . PrintProgress ( organizedModules , _printProgressCancellationTokenSource . Token ) ;
38+
39+ return this ;
4140 }
4241
4342 public async ValueTask DisposeAsync ( )
4443 {
45- _printProgressCancellationTokenSource . CancelAfter ( 5000 ) ;
44+ _printProgressCancellationTokenSource ? . CancelAfter ( 5000 ) ;
4645
4746 await SafelyAwaitProgressPrinter ( ) ;
4847 }
@@ -51,7 +50,10 @@ private async Task SafelyAwaitProgressPrinter()
5150 {
5251 try
5352 {
54- await _printProgressTask ;
53+ if ( _printProgressTask != null )
54+ {
55+ await _printProgressTask ;
56+ }
5557 }
5658 catch ( Exception e )
5759 {
0 commit comments