Skip to content

Make it easier to use cancellation tokens #2271

Closed
@KeithHenry

Description

@KeithHenry

The various SetHandler overloads are great for hooking up simple actions.

However, if you need a cancellation token none of these are available and you have to use:

command.SetHandler(
    async context => 
        await MyMethod(
            context.ParseResult.GetValueForArgument(anArgument)), 
            context.ParseResult.GetValueForOption(anOption),
            context.GetCancellationToken()));

Which feels very clunky compared to the methods without the need for cancellation.

Please could we add:

command.SetCancellableHandler(
    async (arg, opt, token) => 
        await MyMethod(
            arg, 
            opt,
            token), 
    anArgument, 
    anOption);

// or even
command.SetCancellableHandler(
    MyMethod, 
    anArgument, 
    anOption);

I realise this could be done with extension methods, but they wouldn't have access to the internal GetValueForHandlerParameter that the overloads of SetHandler do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions