diff --git a/src/Microsoft.FeatureManagement/FeatureManager.cs b/src/Microsoft.FeatureManagement/FeatureManager.cs index 992c80b4..c9ddb786 100644 --- a/src/Microsoft.FeatureManagement/FeatureManager.cs +++ b/src/Microsoft.FeatureManagement/FeatureManager.cs @@ -71,25 +71,25 @@ public FeatureManager( public Task IsEnabledAsync(string feature) { - return IsEnabledWithVariantsAsync(feature, appContext: null, useAppContext: false, CancellationToken.None); + return IsEnabledWithVariantsAsync(feature, appContext: null, useAppContext: false, CancellationToken.None).AsTask(); } public Task IsEnabledAsync(string feature, TContext appContext) { - return IsEnabledWithVariantsAsync(feature, appContext, useAppContext: true, CancellationToken.None); + return IsEnabledWithVariantsAsync(feature, appContext, useAppContext: true, CancellationToken.None).AsTask(); } - public Task IsEnabledAsync(string feature, CancellationToken cancellationToken) + public ValueTask IsEnabledAsync(string feature, CancellationToken cancellationToken) { return IsEnabledWithVariantsAsync(feature, appContext: null, useAppContext: false, cancellationToken); } - public Task IsEnabledAsync(string feature, TContext appContext, CancellationToken cancellationToken) + public ValueTask IsEnabledAsync(string feature, TContext appContext, CancellationToken cancellationToken) { return IsEnabledWithVariantsAsync(feature, appContext, useAppContext: true, cancellationToken); } - private async Task IsEnabledWithVariantsAsync(string feature, TContext appContext, bool useAppContext, CancellationToken cancellationToken) + private async ValueTask IsEnabledWithVariantsAsync(string feature, TContext appContext, bool useAppContext, CancellationToken cancellationToken) { bool isFeatureEnabled = false; diff --git a/src/Microsoft.FeatureManagement/FeatureManagerSnapshot.cs b/src/Microsoft.FeatureManagement/FeatureManagerSnapshot.cs index 35c4b0ec..6018931d 100644 --- a/src/Microsoft.FeatureManagement/FeatureManagerSnapshot.cs +++ b/src/Microsoft.FeatureManagement/FeatureManagerSnapshot.cs @@ -17,7 +17,7 @@ namespace Microsoft.FeatureManagement class FeatureManagerSnapshot : IFeatureManagerSnapshot, IVariantFeatureManagerSnapshot { private readonly IVariantFeatureManager _featureManager; - private readonly ConcurrentDictionary> _flagCache = new ConcurrentDictionary>(); + private readonly ConcurrentDictionary> _flagCache = new ConcurrentDictionary>(); private readonly ConcurrentDictionary _variantCache = new ConcurrentDictionary(); private IEnumerable _featureNames; @@ -55,24 +55,24 @@ public Task IsEnabledAsync(string feature) { return _flagCache.GetOrAdd( feature, - (key) => _featureManager.IsEnabledAsync(key, CancellationToken.None)); + (key) => _featureManager.IsEnabledAsync(key, CancellationToken.None)).AsTask(); } public Task IsEnabledAsync(string feature, TContext context) { return _flagCache.GetOrAdd( feature, - (key) => _featureManager.IsEnabledAsync(key, context, CancellationToken.None)); + (key) => _featureManager.IsEnabledAsync(key, context, CancellationToken.None)).AsTask(); } - public Task IsEnabledAsync(string feature, CancellationToken cancellationToken) + public ValueTask IsEnabledAsync(string feature, CancellationToken cancellationToken) { return _flagCache.GetOrAdd( feature, (key) => _featureManager.IsEnabledAsync(key, cancellationToken)); } - public Task IsEnabledAsync(string feature, TContext context, CancellationToken cancellationToken) + public ValueTask IsEnabledAsync(string feature, TContext context, CancellationToken cancellationToken) { return _flagCache.GetOrAdd( feature, diff --git a/src/Microsoft.FeatureManagement/IVariantFeatureManager.cs b/src/Microsoft.FeatureManagement/IVariantFeatureManager.cs index 34eea877..0e3add18 100644 --- a/src/Microsoft.FeatureManagement/IVariantFeatureManager.cs +++ b/src/Microsoft.FeatureManagement/IVariantFeatureManager.cs @@ -25,7 +25,7 @@ public interface IVariantFeatureManager /// The name of the feature to check. /// The cancellation token to cancel the operation. /// True if the feature is enabled, otherwise false. - Task IsEnabledAsync(string feature, CancellationToken cancellationToken); + ValueTask IsEnabledAsync(string feature, CancellationToken cancellationToken); /// /// Checks whether a given feature is enabled. @@ -34,7 +34,7 @@ public interface IVariantFeatureManager /// A context providing information that can be used to evaluate whether a feature should be on or off. /// The cancellation token to cancel the operation. /// True if the feature is enabled, otherwise false. - Task IsEnabledAsync(string feature, TContext context, CancellationToken cancellationToken); + ValueTask IsEnabledAsync(string feature, TContext context, CancellationToken cancellationToken); /// /// Gets the assigned variant for a specific feature.