Skip to content

Commit d36a21b

Browse files
authored
Merge pull request #1447 from microsoft/dev/lifengl/allowDetectingCompletedRequests
Add `IPendingExecutionRequestState` interface to expose completion state of `SingleExecuteProtector`
2 parents 43c1138 + 37f9be0 commit d36a21b

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.ComponentModel;
5+
using System.Diagnostics.CodeAnalysis;
6+
7+
namespace Microsoft.VisualStudio.Threading
8+
{
9+
/// <summary>
10+
/// An optional interface implemented by pending request state posted to the underline synchronization context. It allows synchronization context to remove completed requests.
11+
/// </summary>
12+
[EditorBrowsable(EditorBrowsableState.Never)]
13+
[Experimental("VSOnly")]
14+
public interface IPendingExecutionRequestState
15+
{
16+
/// <summary>
17+
/// Gets a value indicating whether the current request has been completed, and can be skipped.
18+
/// </summary>
19+
bool IsCompleted { get; }
20+
}
21+
}

src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,9 @@ public void Dispose()
10581058
/// A delegate wrapper that ensures the delegate is only invoked at most once.
10591059
/// </summary>
10601060
[DebuggerDisplay("{DelegateLabel}")]
1061-
internal class SingleExecuteProtector
1061+
#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.
1062+
internal class SingleExecuteProtector : IPendingExecutionRequestState
1063+
#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.
10621064
{
10631065
/// <summary>
10641066
/// Executes the delegate if it has not already executed.
@@ -1112,6 +1114,11 @@ private SingleExecuteProtector(JoinableTask job)
11121114
this.job = job;
11131115
}
11141116

1117+
/// <summary>
1118+
/// Gets a value indicating whether the current request has been completed, and can be skipped.
1119+
/// </summary>
1120+
bool IPendingExecutionRequestState.IsCompleted => this.HasBeenExecuted;
1121+
11151122
/// <summary>
11161123
/// Gets a value indicating whether this instance has already executed.
11171124
/// </summary>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
Microsoft.VisualStudio.Threading.AsyncBarrier.SignalAndWait(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
2+
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState
3+
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState.IsCompleted.get -> bool
24
static Microsoft.VisualStudio.Threading.JoinableTaskContext.CreateNoOpContext() -> Microsoft.VisualStudio.Threading.JoinableTaskContext!
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
Microsoft.VisualStudio.Threading.AsyncBarrier.SignalAndWait(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
2+
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState
3+
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState.IsCompleted.get -> bool
24
static Microsoft.VisualStudio.Threading.JoinableTaskContext.CreateNoOpContext() -> Microsoft.VisualStudio.Threading.JoinableTaskContext!
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
Microsoft.VisualStudio.Threading.AsyncBarrier.SignalAndWait(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
2+
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState
3+
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState.IsCompleted.get -> bool
24
static Microsoft.VisualStudio.Threading.JoinableTaskContext.CreateNoOpContext() -> Microsoft.VisualStudio.Threading.JoinableTaskContext!
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
Microsoft.VisualStudio.Threading.AsyncBarrier.SignalAndWait(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
2+
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState
3+
Microsoft.VisualStudio.Threading.IPendingExecutionRequestState.IsCompleted.get -> bool
24
static Microsoft.VisualStudio.Threading.JoinableTaskContext.CreateNoOpContext() -> Microsoft.VisualStudio.Threading.JoinableTaskContext!

0 commit comments

Comments
 (0)