Skip to content

Commit 5b188d2

Browse files
committed
fix for #199, Run(CancellationToken) failes compile
1 parent 8960d59 commit 5b188d2

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
using ConsoleAppFramework;
2+
using GeneratorSandbox;
23

3-
args = ["--x", "10", "y", "20"]; // missing argument
4-
ConsoleApp.Run(args, (int x, int y) =>
4+
// fail
5+
//await ConsoleApp.RunAsync(args, Commands.Save);
6+
7+
// fail
8+
await ConsoleApp.RunAsync(args, async () => await Task.Delay(1000, CancellationToken.None));
9+
10+
11+
public class Commands
512
{
6-
Console.WriteLine(new { x, y });
7-
});
13+
/// <summary>
14+
/// Some sort of save command.
15+
/// </summary>
16+
public async Task<int> Save(CancellationToken ct)
17+
{
18+
19+
await Task.Delay(1000);
20+
return 0;
21+
}
22+
}
23+
24+
25+
// `using var posixSignalHandler = PosixSignalHandler.Register(Timeout);`

src/ConsoleAppFramework/Emitter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public void EmitRun(SourceBuilder sb, CommandWithId commandWithId, bool isRunAsy
8585
// prepare argument variables
8686
if (hasCancellationToken)
8787
{
88-
sb.AppendLine("using var posixSignalHandler = PosixSignalHandler.Register(Timeout, __ExternalCancellationToken__);");
88+
var token = command.HasFilter ? "cancellationToken" : emitForBuilder ? "__ExternalCancellationToken__" : "CancellationToken.None";
89+
sb.AppendLine($"using var posixSignalHandler = PosixSignalHandler.Register(Timeout, {token});");
8990
}
9091
if (hasConsoleAppContext)
9192
{

0 commit comments

Comments
 (0)