Skip to content

Commit 14537f6

Browse files
committed
Add CancellationContext comment
1 parent 15bdad0 commit 14537f6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/PowerShellEditorServices/Services/PowerShell/Utility/CancellationContext.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44

55
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility
66
{
7+
/// <summary>
8+
/// Encapsulates the scoping logic for cancellation tokens.
9+
/// As PowerShell commands nest, this class maintains a stack of cancellation scopes
10+
/// that allow each scope of logic to be cancelled at its own level.
11+
/// Implicitly handles the merging and cleanup of cancellation token sources.
12+
/// </summary>
13+
/// <example>
14+
/// The <see cref="Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.CancellationContext"/> class
15+
/// and the <see cref="Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.CancellationScope"/> struct
16+
/// are intended to be used with a <c>using</c> block so you can do this:
17+
/// <code>
18+
/// using (CancellationScope cancellationScope = _cancellationContext.EnterScope(_globalCancellationSource.CancellationToken, localCancellationToken))
19+
/// {
20+
/// ExecuteCommandAsync(command, cancellationScope.CancellationToken);
21+
/// }
22+
/// </code>
23+
/// </example>
724
internal class CancellationContext
825
{
926
private readonly ConcurrentStack<CancellationTokenSource> _cancellationSourceStack;

0 commit comments

Comments
 (0)