1212
1313namespace RemoteExec . Client ;
1414
15- public class RemoteExecutor : IDisposable
15+ public class RemoteExecutor : IAsyncDisposable
1616{
1717 private readonly List < ServerConnection > servers = [ ] ;
1818 private readonly BlockingCollection < PendingTask > globalQueue = [ ] ;
1919 private readonly ConcurrentDictionary < Guid , TaskCompletionSource < RemoteExecutionResult > > pendingResults = new ( ) ;
20+
2021 private CancellationTokenSource distributorCts = new ( ) ;
2122 private Task ? distributorTask ;
23+
2224 private readonly LoadBalancingStrategy loadBalancingStrategy ;
2325 private readonly ILogger logger ;
26+
2427 private bool disposedValue ;
2528
2629 public event EventHandler < ServerMetricsUpdatedEventArgs > ? MetricsUpdated ;
@@ -313,15 +316,19 @@ private sealed class PendingTask
313316 public required DateTime EnqueuedAt { get ; init ; }
314317 }
315318
316- // S2930: Dispose distributorCts when no longer needed
317- protected virtual void Dispose ( bool disposing )
319+ protected virtual async Task DisposeAsync ( bool disposing )
318320 {
319321 if ( ! disposedValue )
320322 {
321323 if ( disposing )
322324 {
323325 distributorCts . Dispose ( ) ;
324- // Dispose managed state (managed objects) here if needed
326+
327+ foreach ( ServerConnection server in servers )
328+ {
329+ await server . Connection . DisposeAsync ( ) ;
330+ server . HttpClient . Dispose ( ) ;
331+ }
325332 }
326333
327334 // Free unmanaged resources (unmanaged objects) and override finalizer if needed
@@ -331,10 +338,9 @@ protected virtual void Dispose(bool disposing)
331338 }
332339 }
333340
334- public void Dispose ( )
341+ public async ValueTask DisposeAsync ( )
335342 {
336- // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
337- Dispose ( disposing : true ) ;
343+ await DisposeAsync ( disposing : true ) ;
338344 GC . SuppressFinalize ( this ) ;
339345 }
340346}
0 commit comments