Skip to content

Commit

Permalink
Added cancellation token and configureawait.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyca15 committed Jul 27, 2021
1 parent 25dcd7f commit 5fe6e51
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;

namespace FeatureFlagDemo
Expand All @@ -23,7 +24,7 @@ public HttpContextTargetingContextAccessor(IHttpContextAccessor httpContextAcces
_httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
}

public ValueTask<TargetingContext> GetContextAsync()
public ValueTask<TargetingContext> GetContextAsync(CancellationToken _)
{
HttpContext httpContext = _httpContextAccessor.HttpContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
IEnumerable<string> names = Name.Split(',').Select(n => n.Trim());

enabled = Requirement == RequirementType.All ?
await names.All(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false)) :
await names.Any(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false));
await names.All(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false) :
await names.Any(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false);
}

if (Negate)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.FeatureManagement.FeatureFilters
Expand All @@ -13,7 +14,8 @@ public interface ITargetingContextAccessor
/// <summary>
/// Retrieves the current targeting context.
/// </summary>
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
/// <returns>The current targeting context.</returns>
ValueTask<TargetingContext> GetContextAsync();
ValueTask<TargetingContext> GetContextAsync(CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, Ca

//
// Acquire targeting context via accessor
TargetingContext targetingContext = await _contextAccessor.GetContextAsync().ConfigureAwait(false);
TargetingContext targetingContext = await _contextAccessor.GetContextAsync(cancellationToken).ConfigureAwait(false);

//
// Ensure targeting can be performed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.
//
using Microsoft.FeatureManagement.FeatureFilters;
using System.Threading;
using System.Threading.Tasks;

namespace Tests.FeatureManagement
Expand All @@ -10,7 +11,7 @@ class OnDemandTargetingContextAccessor : ITargetingContextAccessor
{
public TargetingContext Current { get; set; }

public ValueTask<TargetingContext> GetContextAsync()
public ValueTask<TargetingContext> GetContextAsync(CancellationToken _)
{
return new ValueTask<TargetingContext>(Current);
}
Expand Down

0 comments on commit 5fe6e51

Please sign in to comment.