feat: Add Cancellation API on StreamingRun (#1675)

This commit is contained in:
Jacob Alber
2025-10-23 16:01:56 -04:00
committed by GitHub
Unverified
parent b2246efa69
commit 3aa682082a
2 changed files with 17 additions and 7 deletions
@@ -156,15 +156,22 @@ internal sealed class AsyncRunHandle : ICheckpointingHandle, IAsyncDisposable
this._eventStream.SignalInput();
}
public async ValueTask CancelRunAsync()
{
this._endRunSource.Cancel();
await this._eventStream.StopAsync().ConfigureAwait(false);
}
public async ValueTask DisposeAsync()
{
if (Interlocked.Exchange(ref this._isDisposed, 1) == 0)
{
this._endRunSource.Cancel();
// Cancel the run if it is still running
await this.CancelRunAsync().ConfigureAwait(false);
await this._eventStream.StopAsync().ConfigureAwait(false);
// These actually release and clean up resources
await this._stepRunner.RequestEndRunAsync().ConfigureAwait(false);
this._endRunSource.Dispose();
await this._eventStream.DisposeAsync().ConfigureAwait(false);
@@ -79,11 +79,14 @@ public sealed class StreamingRun : IAsyncDisposable
CancellationToken cancellationToken = default)
=> this._runHandle.TakeEventStreamAsync(blockOnPendingRequest, cancellationToken);
/// <summary>
/// Attempt to cancel the streaming run.
/// </summary>
/// <returns>A <see cref="ValueTask"/> that represents the asynchronous send operation.</returns>
public ValueTask CancelRunAsync() => this._runHandle.CancelRunAsync();
/// <inheritdoc/>
public ValueTask DisposeAsync()
{
return this._runHandle.DisposeAsync();
}
public ValueTask DisposeAsync() => this._runHandle.DisposeAsync();
}
/// <summary>