Skip to content

Commit 5fe6e51

Browse files
committed
Added cancellation token and configureawait.
1 parent 25dcd7f commit 5fe6e51

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

examples/FeatureFlagDemo/HttpContextTargetingContextAccessor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Collections.Generic;
88
using System.Security.Claims;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011

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

26-
public ValueTask<TargetingContext> GetContextAsync()
27+
public ValueTask<TargetingContext> GetContextAsync(CancellationToken _)
2728
{
2829
HttpContext httpContext = _httpContextAccessor.HttpContext;
2930

src/Microsoft.FeatureManagement.AspNetCore/TagHelpers/FeatureTagHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
5656
IEnumerable<string> names = Name.Split(',').Select(n => n.Trim());
5757

5858
enabled = Requirement == RequirementType.All ?
59-
await names.All(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false)) :
60-
await names.Any(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false));
59+
await names.All(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false) :
60+
await names.Any(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false);
6161
}
6262

6363
if (Negate)

src/Microsoft.FeatureManagement/Targeting/ITargetingContextAccessor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33
//
4+
using System.Threading;
45
using System.Threading.Tasks;
56

67
namespace Microsoft.FeatureManagement.FeatureFilters
@@ -13,7 +14,8 @@ public interface ITargetingContextAccessor
1314
/// <summary>
1415
/// Retrieves the current targeting context.
1516
/// </summary>
17+
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
1618
/// <returns>The current targeting context.</returns>
17-
ValueTask<TargetingContext> GetContextAsync();
19+
ValueTask<TargetingContext> GetContextAsync(CancellationToken cancellationToken);
1820
}
1921
}

src/Microsoft.FeatureManagement/Targeting/TargetingFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, Ca
4949

5050
//
5151
// Acquire targeting context via accessor
52-
TargetingContext targetingContext = await _contextAccessor.GetContextAsync().ConfigureAwait(false);
52+
TargetingContext targetingContext = await _contextAccessor.GetContextAsync(cancellationToken).ConfigureAwait(false);
5353

5454
//
5555
// Ensure targeting can be performed

tests/Tests.FeatureManagement/OnDemandTargetingContextAccessor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33
//
44
using Microsoft.FeatureManagement.FeatureFilters;
5+
using System.Threading;
56
using System.Threading.Tasks;
67

78
namespace Tests.FeatureManagement
@@ -10,7 +11,7 @@ class OnDemandTargetingContextAccessor : ITargetingContextAccessor
1011
{
1112
public TargetingContext Current { get; set; }
1213

13-
public ValueTask<TargetingContext> GetContextAsync()
14+
public ValueTask<TargetingContext> GetContextAsync(CancellationToken _)
1415
{
1516
return new ValueTask<TargetingContext>(Current);
1617
}

0 commit comments

Comments
 (0)