Skip to content

Commit 9556888

Browse files
committed
Add support for IAsyncDisposable to schema services.
1 parent 48309bf commit 9556888

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/HotChocolate/Core/src/Execution/RequestExecutorResolver.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace HotChocolate.Execution;
2323
internal sealed partial class RequestExecutorResolver
2424
: IRequestExecutorResolver
2525
, IRequestExecutorWarmup
26-
, IDisposable
26+
, IAsyncDisposable
2727
{
2828
private readonly CancellationTokenSource _cts = new();
2929
private readonly ConcurrentDictionary<string, SemaphoreSlim> _semaphoreBySchema = new();
@@ -253,7 +253,7 @@ private static async Task RunEvictionEvents(RegisteredExecutor registeredExecuto
253253
// we will give the request executor some grace period to finish all request
254254
// in the pipeline.
255255
await Task.Delay(TimeSpan.FromMinutes(5));
256-
registeredExecutor.Dispose();
256+
await registeredExecutor.DisposeAsync();
257257
}
258258
}
259259

@@ -498,16 +498,16 @@ private static RequestDelegate CreatePipeline(
498498
return next;
499499
}
500500

501-
public void Dispose()
501+
public async ValueTask DisposeAsync()
502502
{
503503
if (!_disposed)
504504
{
505505
// this will stop the eviction processor.
506-
_cts.Cancel();
506+
await _cts.CancelAsync();
507507

508508
foreach (var executor in _executors.Values)
509509
{
510-
executor.Dispose();
510+
await executor.DisposeAsync();
511511
}
512512

513513
foreach (var semaphore in _semaphoreBySchema.Values)
@@ -529,7 +529,7 @@ private sealed class RegisteredExecutor(
529529
IExecutionDiagnosticEvents diagnosticEvents,
530530
RequestExecutorSetup setup,
531531
TypeModuleChangeMonitor typeModuleChangeMonitor)
532-
: IDisposable
532+
: IAsyncDisposable
533533
{
534534
private bool _disposed;
535535

@@ -543,13 +543,19 @@ private sealed class RegisteredExecutor(
543543

544544
public TypeModuleChangeMonitor TypeModuleChangeMonitor { get; } = typeModuleChangeMonitor;
545545

546-
public void Dispose()
546+
public async ValueTask DisposeAsync()
547547
{
548548
if (!_disposed)
549549
{
550-
if (Services is IDisposable d)
550+
switch (Services)
551551
{
552-
d.Dispose();
552+
case IAsyncDisposable asyncDisposable:
553+
await asyncDisposable.DisposeAsync();
554+
break;
555+
556+
case IDisposable d:
557+
d.Dispose();
558+
break;
553559
}
554560

555561
TypeModuleChangeMonitor.Dispose();

0 commit comments

Comments
 (0)