Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions NxGraph/Fsm/Async/AsyncRelayState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public sealed class AsyncRelayState(
Func<CancellationToken, ValueTask<Result>> run,
Func<CancellationToken, ValueTask<Result>>? onEnter = null,
Func<CancellationToken, ValueTask>? onExit = null)
Func<CancellationToken, ValueTask<Result>>? onExit = null)
: AsyncState
{
private readonly Func<CancellationToken, ValueTask<Result>> _run = run ?? throw new ArgumentNullException(nameof(run));
Expand All @@ -24,9 +24,9 @@ protected override ValueTask<Result> OnRunAsync(CancellationToken ct)
return _run(ct);
}

protected override ValueTask OnExitAsync(CancellationToken ct)
protected override ValueTask<Result> OnExitAsync(CancellationToken ct)
{
return onExit?.Invoke(ct) ?? default;
return onExit?.Invoke(ct) ?? ResultHelpers.Success;
}
}

Expand All @@ -40,7 +40,7 @@ protected override ValueTask OnExitAsync(CancellationToken ct)
public sealed class AsyncRelayState<TAgent>(
Func<TAgent, CancellationToken, ValueTask<Result>> run,
Func<TAgent, CancellationToken, ValueTask<Result>>? onEnter = null,
Func<TAgent, CancellationToken, ValueTask>? onExit = null)
Func<TAgent, CancellationToken, ValueTask<Result>>? onExit = null)
: AsyncState<TAgent>
{
private readonly Func<TAgent, CancellationToken, ValueTask<Result>> _run = run ?? throw new ArgumentNullException(nameof(run));
Expand All @@ -55,8 +55,8 @@ protected override ValueTask<Result> OnRunAsync(CancellationToken ct)
return _run(Agent, ct);
}

protected override ValueTask OnExitAsync(CancellationToken ct)
protected override ValueTask<Result> OnExitAsync(CancellationToken ct)
{
return onExit?.Invoke(Agent, ct) ?? default;
return onExit?.Invoke(Agent, ct) ?? ResultHelpers.Success;
}
}
4 changes: 2 additions & 2 deletions NxGraph/Fsm/Async/AsyncState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ protected virtual ValueTask<Result> OnRunAsync(CancellationToken ct)
return ResultHelpers.Continue;
}

protected virtual ValueTask OnExitAsync(CancellationToken ct)
protected virtual ValueTask<Result> OnExitAsync(CancellationToken ct)
{
return default;
return ResultHelpers.Success;
}
}

Expand Down
10 changes: 5 additions & 5 deletions NxGraph/Fsm/Async/AsyncStateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ await TransitionTo(result == Result.Success ? ExecutionStatus.Completed : Execut
}
}

protected override ValueTask OnExitAsync(CancellationToken ct)
protected override ValueTask<Result> OnExitAsync(CancellationToken ct)
{
// For Ignore policy, OnEnterAsync returns early with the gate held.
// We want OnRunAsync to run and return the terminal result, and then
// OnExitAsync will release the gate in the normal way.
Volatile.Write(ref _executeGate, 0);
return ResultHelpers.CompletedTask;
return ResultHelpers.Success;
}

private async ValueTask<Result> InternalRunAsync(CancellationToken ct)
Expand All @@ -239,8 +239,8 @@ private async ValueTask<Result> InternalRunAsync(CancellationToken ct)
}
}

LogicNode logicLogicNode = (LogicNode)node;
Result result = await logicLogicNode.AsyncLogic.ExecuteAsync(ct).ConfigureAwait(false);
LogicNode logic = (LogicNode)node;
Result result = await logic.AsyncLogic.ExecuteAsync(ct).ConfigureAwait(false);
switch (result.Code)
{
case Result.StatusCode.Success:
Expand All @@ -252,7 +252,7 @@ private async ValueTask<Result> InternalRunAsync(CancellationToken ct)

NodeId next;

if (logicLogicNode.AsyncLogic is IAsyncDirector director)
if (logic.AsyncLogic is IAsyncDirector director)
{
next = await director.SelectNextAsync(ct).ConfigureAwait(false);
if (next.Equals(NodeId.Default))
Expand Down
Loading