Skip to content

Commit 2cc95df

Browse files
committed
Invoke WaitAsync directly for Task returning methods
1 parent 1698233 commit 2cc95df

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/ConsoleAppFramework/Emitter.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,14 @@ public void EmitRun(SourceBuilder sb, CommandWithId commandWithId, bool isRunAsy
386386

387387
if (hasCancellationToken)
388388
{
389-
invokeCommand = $"Task.Run(() => {invokeCommand}).WaitAsync(posixSignalHandler.TimeoutToken)";
389+
if (command.IsAsync)
390+
{
391+
invokeCommand = $"{invokeCommand}.WaitAsync(posixSignalHandler.TimeoutToken)";
392+
}
393+
else
394+
{
395+
invokeCommand = $"Task.Run(() => {invokeCommand}).WaitAsync(posixSignalHandler.TimeoutToken)";
396+
}
390397
}
391398
if (command.IsAsync || hasCancellationToken)
392399
{

0 commit comments

Comments
 (0)