vezel-dev / cathode

A terminal-centric replacement for the .NET console APIs.
https://docs.vezel.dev/cathode
BSD Zero Clause License
91 stars 7 forks source link

Offer `CancellationToken` support in `IProgram` (.NET 7) #86

Closed alexrp closed 1 year ago

alexrp commented 2 years ago

Depends on:

Something like:

public interface IProgram
{
    public static virtual bool SupportsCancellation => true;

    public static abstract Task RunAsync(ProgramContext context);
}

If SupportsCancellation is true, ProgramHost will wire up a Signaled event handler to trigger a CancellationTokenSource whose CancellationToken gets passed as a property on ProgramContext.

(The reason for making cancellation support optional is that wiring up Signaled has side effects that may not be tolerable - see #64.)

alexrp commented 2 years ago

This can only happen in .NET 7 as the Roslyn shipped with .NET 6 does not support static virtual members.