mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
27 lines
746 B
C#
27 lines
746 B
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using CliFx.Attributes;
|
|
|
|
namespace CliFx.Tests
|
|
{
|
|
public partial class CancellationSpecs
|
|
{
|
|
[Command("cancel")]
|
|
private class CancellableCommand : ICommand
|
|
{
|
|
public async ValueTask ExecuteAsync(IConsole console)
|
|
{
|
|
try
|
|
{
|
|
await Task.Delay(TimeSpan.FromSeconds(3), console.GetCancellationToken());
|
|
console.Output.WriteLine("Never printed");
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
console.Output.WriteLine("Cancellation requested");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |