dotnet / dotnet/command-line-api

CommandHandler.GetExitCodeAsync only awaits Task<int> return types

Open
#2,314 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

I believe it would make sense that `GetExitCodeAsync`:
https://github.com/dotnet/command-line-api/blob/a0782c85fd8f7aed16f46935998e9280c86ed2fb/src/System.CommandLine.NamingConventionBinder/CommandHandler.cs#L607

Should await any return object that is a descendant of the `Task` type. If the type is `Task` the `int` value should be returned, otherwise, return 0.

As it stands, an asynchronous method used as a command handler that does not return an `int` is unlikely to run to completion if the System.CommandLine.Hosting code is used.

This can be seen easily in:

https://github.com/dotnet/command-line-api/blob/a0782c85fd8f7aed16f46935998e9280c86ed2fb/samples/HostingPlayground/Program.cs#L36

by adding an `await Task.Delay(TimeSpan.FromSeconds(10));` to force the `Run` method to yield.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.