Skip to content

Commit e05591c

Browse files
authored
Adjusts IVarantManager to use ValueTask (#293)
1 parent 197c325 commit e05591c

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/Microsoft.FeatureManagement/FeatureManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,25 @@ public FeatureManager(
7171

7272
public Task<bool> IsEnabledAsync(string feature)
7373
{
74-
return IsEnabledWithVariantsAsync<object>(feature, appContext: null, useAppContext: false, CancellationToken.None);
74+
return IsEnabledWithVariantsAsync<object>(feature, appContext: null, useAppContext: false, CancellationToken.None).AsTask();
7575
}
7676

7777
public Task<bool> IsEnabledAsync<TContext>(string feature, TContext appContext)
7878
{
79-
return IsEnabledWithVariantsAsync(feature, appContext, useAppContext: true, CancellationToken.None);
79+
return IsEnabledWithVariantsAsync(feature, appContext, useAppContext: true, CancellationToken.None).AsTask();
8080
}
8181

82-
public Task<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken)
82+
public ValueTask<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken)
8383
{
8484
return IsEnabledWithVariantsAsync<object>(feature, appContext: null, useAppContext: false, cancellationToken);
8585
}
8686

87-
public Task<bool> IsEnabledAsync<TContext>(string feature, TContext appContext, CancellationToken cancellationToken)
87+
public ValueTask<bool> IsEnabledAsync<TContext>(string feature, TContext appContext, CancellationToken cancellationToken)
8888
{
8989
return IsEnabledWithVariantsAsync(feature, appContext, useAppContext: true, cancellationToken);
9090
}
9191

92-
private async Task<bool> IsEnabledWithVariantsAsync<TContext>(string feature, TContext appContext, bool useAppContext, CancellationToken cancellationToken)
92+
private async ValueTask<bool> IsEnabledWithVariantsAsync<TContext>(string feature, TContext appContext, bool useAppContext, CancellationToken cancellationToken)
9393
{
9494
bool isFeatureEnabled = false;
9595

src/Microsoft.FeatureManagement/FeatureManagerSnapshot.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Microsoft.FeatureManagement
1717
class FeatureManagerSnapshot : IFeatureManagerSnapshot, IVariantFeatureManagerSnapshot
1818
{
1919
private readonly IVariantFeatureManager _featureManager;
20-
private readonly ConcurrentDictionary<string, Task<bool>> _flagCache = new ConcurrentDictionary<string, Task<bool>>();
20+
private readonly ConcurrentDictionary<string, ValueTask<bool>> _flagCache = new ConcurrentDictionary<string, ValueTask<bool>>();
2121
private readonly ConcurrentDictionary<string, Variant> _variantCache = new ConcurrentDictionary<string, Variant>();
2222
private IEnumerable<string> _featureNames;
2323

@@ -55,24 +55,24 @@ public Task<bool> IsEnabledAsync(string feature)
5555
{
5656
return _flagCache.GetOrAdd(
5757
feature,
58-
(key) => _featureManager.IsEnabledAsync(key, CancellationToken.None));
58+
(key) => _featureManager.IsEnabledAsync(key, CancellationToken.None)).AsTask();
5959
}
6060

6161
public Task<bool> IsEnabledAsync<TContext>(string feature, TContext context)
6262
{
6363
return _flagCache.GetOrAdd(
6464
feature,
65-
(key) => _featureManager.IsEnabledAsync(key, context, CancellationToken.None));
65+
(key) => _featureManager.IsEnabledAsync(key, context, CancellationToken.None)).AsTask();
6666
}
6767

68-
public Task<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken)
68+
public ValueTask<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken)
6969
{
7070
return _flagCache.GetOrAdd(
7171
feature,
7272
(key) => _featureManager.IsEnabledAsync(key, cancellationToken));
7373
}
7474

75-
public Task<bool> IsEnabledAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken)
75+
public ValueTask<bool> IsEnabledAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken)
7676
{
7777
return _flagCache.GetOrAdd(
7878
feature,

src/Microsoft.FeatureManagement/IVariantFeatureManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface IVariantFeatureManager
2525
/// <param name="feature">The name of the feature to check.</param>
2626
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
2727
/// <returns>True if the feature is enabled, otherwise false.</returns>
28-
Task<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken);
28+
ValueTask<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken);
2929

3030
/// <summary>
3131
/// Checks whether a given feature is enabled.
@@ -34,7 +34,7 @@ public interface IVariantFeatureManager
3434
/// <param name="context">A context providing information that can be used to evaluate whether a feature should be on or off.</param>
3535
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
3636
/// <returns>True if the feature is enabled, otherwise false.</returns>
37-
Task<bool> IsEnabledAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken);
37+
ValueTask<bool> IsEnabledAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken);
3838

3939
/// <summary>
4040
/// Gets the assigned variant for a specific feature.

0 commit comments

Comments
 (0)