Skip to content

Add IPendingExecutionRequestState interface to expose completion state of SingleExecuteProtector #1447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.VisualStudio.Threading
{
/// <summary>
/// An optional interface implemented by pending request state posted to the underline synchronization context. It allows synchronization context to remove completed requests.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Experimental("VSOnly")]
public interface IPendingExecutionRequestState
{
/// <summary>
/// Gets a value indicating whether the current request has been completed, and can be skipped.
/// </summary>
bool IsCompleted { get; }
}
}
9 changes: 8 additions & 1 deletion src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,9 @@ public void Dispose()
/// A delegate wrapper that ensures the delegate is only invoked at most once.
/// </summary>
[DebuggerDisplay("{DelegateLabel}")]
internal class SingleExecuteProtector
#pragma warning disable VSOnly // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
internal class SingleExecuteProtector : IPendingExecutionRequestState
#pragma warning restore VSOnly // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
{
/// <summary>
/// Executes the delegate if it has not already executed.
Expand Down Expand Up @@ -1112,6 +1114,11 @@ private SingleExecuteProtector(JoinableTask job)
this.job = job;
}

/// <summary>
/// Gets a value indicating whether the current request has been completed, and can be skipped.
/// </summary>
bool IPendingExecutionRequestState.IsCompleted => this.HasBeenExecuted;

/// <summary>
/// Gets a value indicating whether this instance has already executed.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Microsoft.VisualStudio.Threading.AsyncBarrier.SignalAndWait(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState.IsCompleted.get -> bool
static Microsoft.VisualStudio.Threading.JoinableTaskContext.CreateNoOpContext() -> Microsoft.VisualStudio.Threading.JoinableTaskContext!
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Microsoft.VisualStudio.Threading.AsyncBarrier.SignalAndWait(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState.IsCompleted.get -> bool
static Microsoft.VisualStudio.Threading.JoinableTaskContext.CreateNoOpContext() -> Microsoft.VisualStudio.Threading.JoinableTaskContext!
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Microsoft.VisualStudio.Threading.AsyncBarrier.SignalAndWait(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState.IsCompleted.get -> bool
static Microsoft.VisualStudio.Threading.JoinableTaskContext.CreateNoOpContext() -> Microsoft.VisualStudio.Threading.JoinableTaskContext!
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Microsoft.VisualStudio.Threading.AsyncBarrier.SignalAndWait(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState.IsCompleted.get -> bool
static Microsoft.VisualStudio.Threading.JoinableTaskContext.CreateNoOpContext() -> Microsoft.VisualStudio.Threading.JoinableTaskContext!