mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
feat: Add Cancellation API on StreamingRun (#1675)
This commit is contained in:
committed by
GitHub
Unverified
parent
b2246efa69
commit
3aa682082a
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user