Skip to content

Commit 4a13466

Browse files
committed
feat: Simplify function-to-executor pattern
1 parent 6a72b58 commit 4a13466

File tree

3 files changed

+207
-21
lines changed

3 files changed

+207
-21
lines changed

dotnet/samples/GettingStarted/Workflows/_Foundational/01_ExecutorsAndEdges/Program.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public static class Program
2020
private static async Task Main()
2121
{
2222
// Create the executors
23-
UppercaseExecutor uppercase = new();
23+
Func<string, string> uppercaseFunc = s => s.ToUpperInvariant();
24+
var uppercase = uppercaseFunc.AsExecutor("UppercaseExecutor");
25+
2426
ReverseTextExecutor reverse = new();
2527

2628
// Build the workflow by connecting executors sequentially
@@ -40,23 +42,6 @@ private static async Task Main()
4042
}
4143
}
4244

43-
/// <summary>
44-
/// First executor: converts input text to uppercase.
45-
/// </summary>
46-
internal sealed class UppercaseExecutor() : Executor<string, string>("UppercaseExecutor")
47-
{
48-
/// <summary>
49-
/// Processes the input message by converting it to uppercase.
50-
/// </summary>
51-
/// <param name="message">The input text to convert</param>
52-
/// <param name="context">Workflow context for accessing workflow services and adding events</param>
53-
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests.
54-
/// The default is <see cref="CancellationToken.None"/>.</param>
55-
/// <returns>The input text converted to uppercase</returns>
56-
public override ValueTask<string> HandleAsync(string message, IWorkflowContext context, CancellationToken cancellationToken = default) =>
57-
ValueTask.FromResult(message.ToUpperInvariant()); // The return value will be sent as a message along an edge to subsequent executors
58-
}
59-
6045
/// <summary>
6146
/// Second executor: reverses the input text and completes the workflow.
6247
/// </summary>

0 commit comments

Comments
 (0)