mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
31 lines
819 B
C#
31 lines
819 B
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using CliFx.Attributes;
|
|
|
|
namespace CliFx.Tests.Commands
|
|
{
|
|
[Command("cmd")]
|
|
public class CancellableCommand : ICommand
|
|
{
|
|
public const string CompletionOutputText = "Finished";
|
|
public const string CancellationOutputText = "Canceled";
|
|
|
|
public async ValueTask ExecuteAsync(IConsole console)
|
|
{
|
|
try
|
|
{
|
|
await Task.Delay(
|
|
TimeSpan.FromSeconds(3),
|
|
console.GetCancellationToken()
|
|
);
|
|
|
|
console.Output.WriteLine(CompletionOutputText);
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
console.Output.WriteLine(CancellationOutputText);
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
} |