Skip to content

Commit

Permalink
Add cancellation token support
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmholt committed Oct 13, 2021
1 parent 4617938 commit 1eab605
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions PSReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public partial class PSConsoleReadLine : IPSConsoleReadLineMockableMethods

private static readonly CancellationToken _defaultCancellationToken = new CancellationTokenSource().Token;

private static Action _handleIdleOverride;
// This exists for PowerShell Editor Services (the backend of the PowerShell VSCode extension)
// so that it can call PSReadLine from a delegate and not hit nested pipeline issues
private static Action<CancellationToken> _handleIdleOverride;

private bool _delayedOneTimeInitCompleted;

Expand Down Expand Up @@ -203,9 +205,9 @@ internal static PSKeyInfo ReadKey()
if (handleId != WaitHandle.WaitTimeout && handleId != EventProcessingRequested)
break;

if (_handleIdleOverride != null)
if (_handleIdleOverride is not null)
{
_handleIdleOverride();
_handleIdleOverride(_singleton._cancelReadCancellationToken);
continue;
}

Expand Down

0 comments on commit 1eab605

Please sign in to comment.