// Copyright (c) Microsoft. All rights reserved. using System.Threading; using System.Threading.Tasks; namespace Microsoft.Agents.AI.Workflows.Execution; internal static class AsyncRunHandleExtensions { public static async ValueTask EnqueueAndStreamAsync(this AsyncRunHandle runHandle, TInput input, CancellationToken cancellationToken = default) { await runHandle.EnqueueMessageAsync(input, cancellationToken).ConfigureAwait(false); return new(runHandle); } public static async ValueTask EnqueueUntypedAndStreamAsync(this AsyncRunHandle runHandle, object input, CancellationToken cancellationToken = default) { await runHandle.EnqueueMessageUntypedAsync(input, cancellationToken: cancellationToken).ConfigureAwait(false); return new(runHandle); } public static async ValueTask EnqueueAndRunAsync(this AsyncRunHandle runHandle, TInput input, CancellationToken cancellationToken = default) { await runHandle.EnqueueMessageAsync(input, cancellationToken).ConfigureAwait(false); Run run = new(runHandle); await run.RunToNextHaltAsync(cancellationToken).ConfigureAwait(false); return run; } public static async ValueTask EnqueueUntypedAndRunAsync(this AsyncRunHandle runHandle, object input, CancellationToken cancellationToken = default) { await runHandle.EnqueueMessageUntypedAsync(input, cancellationToken: cancellationToken).ConfigureAwait(false); Run run = new(runHandle); await run.RunToNextHaltAsync(cancellationToken).ConfigureAwait(false); return run; } }