Skip to content

Commit

Permalink
Merge pull request #67196 from CyrusNajmabadi/expeditableDelay
Browse files Browse the repository at this point in the history
Move to an expeditable delay to help out tests.
  • Loading branch information
CyrusNajmabadi authored Mar 6, 2023
2 parents 5f38bc8 + da06caa commit 42708be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.DesignerAttribute
Expand All @@ -30,6 +31,8 @@ internal sealed partial class DesignerAttributeDiscoveryService : IDesignerAttri
/// </summary>
private static readonly ConditionalWeakTable<IReadOnlyList<MetadataReference>, AsyncLazy<bool>> s_metadataReferencesToDesignerAttributeInfo = new();

private readonly IAsynchronousOperationListener _listener;

/// <summary>
/// Protects mutable state in this type.
/// </summary>
Expand All @@ -43,8 +46,9 @@ internal sealed partial class DesignerAttributeDiscoveryService : IDesignerAttri

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public DesignerAttributeDiscoveryService()
public DesignerAttributeDiscoveryService(IAsynchronousOperationListenerProvider listenerProvider)
{
_listener = listenerProvider.GetListener(FeatureAttribute.DesignerAttributes);
}

private static AsyncLazy<bool> GetLazyHasDesignerCategoryType(Project project)
Expand Down Expand Up @@ -79,7 +83,7 @@ public async ValueTask ProcessSolutionAsync(
await ProcessProjectAsync(priorityDocument.Project, priorityDocument, useFrozenSnapshots, callback, cancellationToken).ConfigureAwait(false);

// Wait a little after the priority document and process the rest at a lower priority.
await Task.Delay(DelayTimeSpan.NonFocus, cancellationToken).ConfigureAwait(false);
await _listener.Delay(DelayTimeSpan.NonFocus, cancellationToken).ConfigureAwait(false);

// Process the rest of the projects in dependency order so that their data is ready when we hit the
// projects that depend on them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal interface IExpeditableDelaySource
/// <para>The <paramref name="delay"/> argument's <see cref="TimeSpan.TotalMilliseconds"/> property is greater than <see cref="int.MaxValue"/>.</para>
/// </exception>
/// <exception cref="OperationCanceledException">The delay has been canceled.</exception>
[SuppressMessage("Style", "VSTHRD200:Use \"Async\" suffix for async methods", Justification = "Named after 'Task.Delay'")]
[SuppressMessage("Style", """VSTHRD200:Use "Async" suffix for async methods""", Justification = "Named after 'Task.Delay'")]
Task<bool> Delay(TimeSpan delay, CancellationToken cancellationToken);
}
}

0 comments on commit 42708be

Please sign in to comment.