Skip to content

TimeoutExecutor

NexusLabs.Needlr.AgentFramework.Workflows

NexusLabs.Needlr.AgentFramework.Workflows.Sequential

TimeoutExecutor Class

Wraps an executor with a maximum execution duration. If the inner executor does not complete within the specified timeout, the linked cancellation token is triggered.

public sealed class TimeoutExecutor : NexusLabs.Needlr.AgentFramework.Workflows.Sequential.IStageExecutor

Inheritance System.Object 🡒 TimeoutExecutor

Implements IStageExecutor

Example

var executor = new TimeoutExecutor(innerExecutor, TimeSpan.FromSeconds(30));

// Throws OperationCanceledException if inner takes longer than 30 seconds.
var result = await executor.ExecuteAsync(context, cancellationToken);

Constructors

TimeoutExecutor(IStageExecutor, TimeSpan) Constructor

Wraps an executor with a maximum execution duration. If the inner executor does not complete within the specified timeout, the linked cancellation token is triggered.

public TimeoutExecutor(NexusLabs.Needlr.AgentFramework.Workflows.Sequential.IStageExecutor inner, System.TimeSpan timeout);

Parameters

inner IStageExecutor

The executor to wrap.

timeout System.TimeSpan

The maximum duration before cancellation.

Example

var executor = new TimeoutExecutor(innerExecutor, TimeSpan.FromSeconds(30));

// Throws OperationCanceledException if inner takes longer than 30 seconds.
var result = await executor.ExecuteAsync(context, cancellationToken);

Methods

TimeoutExecutor.ExecuteAsync(StageExecutionContext, CancellationToken) Method

Executes the stage logic and returns a result indicating success or failure.

public System.Threading.Tasks.Task<NexusLabs.Needlr.AgentFramework.Workflows.Sequential.StageExecutionResult> ExecuteAsync(NexusLabs.Needlr.AgentFramework.Workflows.Sequential.StageExecutionContext context, System.Threading.CancellationToken cancellationToken);

Parameters

context StageExecutionContext

The execution context providing access to shared pipeline state.

cancellationToken System.Threading.CancellationToken

Token to observe for cancellation.

Implements ExecuteAsync(StageExecutionContext, CancellationToken)

Returns

System.Threading.Tasks.Task<StageExecutionResult>
A StageExecutionResult describing the outcome.