Skip to content

Common Parameters should include a CancellationToken #19685

Open

Description

@rhubarb-geek-nz

Summary of the new feature / enhancement

There have been a number of requests to add timeouts to various commands ( why always in seconds ? ) it would be simpler to add CancellationToken support to Common Parameters so that all commands automatically have the capability in a consistent manner.

While superficially a timeout might seem obvious and simple, a CancellationToken is far more useful and allows the client control over when the cancellation is requested, eg not just because of a timeout but because some other condition occurred after the command has been started.

Proposed technical implementation details (optional)

Proof of concept

This demonstrates a cancellation token working with Invoke-Command

Implementation - CommandWithCancellationToken.cs

Unit tests - CommandWithCancellationTokenTests.cs

Activity

  1. added
    Issue-Enhancement
    Needs-Triage
    on May 20, 2023
  2. kasini3000 commented on May 21, 2023

    @kasini3000

    While superficially a timeout might seem obvious and simple, a CancellationToken is far more useful and allows the client control over when the cancellation is requested

    Both of these are required.
    I reiterate that it is important for multithreading. Powershell is different from shell, as it works at the multi-threaded level.

    PowerShell/ThreadJob#26

  3. added
    Resolution-No Activity
    and removed
    Resolution-No Activity
    on Nov 18, 2023
  4. added
    WG-Engine
    on Jan 18, 2024
  5. Zetanova commented on Apr 4, 2024

    @Zetanova

    I found a method to get the SIGINT signal (windows and linux) from the pwsh.exe to be useable for sync-over-async calls on
    gist signal-cancellation

  6. Zetanova commented on Apr 5, 2024

    @Zetanova

    Yes, until the powershell team implements something they dont want to implement for years.
    This SignalToken can be used to abort scripts in the pwsh.exe on script creation time.

    The other option is off to kill pwsh.exe and open it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-EnhancementNeeds-TriageWG-Engine

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions