5
5
using System ;
6
6
using System . Collections . Concurrent ;
7
7
using System . Collections . Generic ;
8
+ using System . Runtime . CompilerServices ;
8
9
using System . Threading ;
9
10
using System . Threading . Tasks ;
10
11
@@ -15,23 +16,28 @@ namespace Microsoft.FeatureManagement
15
16
/// </summary>
16
17
class FeatureManagerSnapshot : IFeatureManagerSnapshot , IVariantFeatureManagerSnapshot
17
18
{
18
- private readonly FeatureManager _featureManager ;
19
+ private readonly IVariantFeatureManager _featureManager ;
19
20
private readonly ConcurrentDictionary < string , Task < bool > > _flagCache = new ConcurrentDictionary < string , Task < bool > > ( ) ;
20
21
private readonly ConcurrentDictionary < string , Variant > _variantCache = new ConcurrentDictionary < string , Variant > ( ) ;
21
22
private IEnumerable < string > _featureNames ;
22
23
23
- public FeatureManagerSnapshot ( FeatureManager featureManager )
24
+ public FeatureManagerSnapshot ( IVariantFeatureManager featureManager )
24
25
{
25
26
_featureManager = featureManager ?? throw new ArgumentNullException ( nameof ( featureManager ) ) ;
26
27
}
27
28
28
- public async IAsyncEnumerable < string > GetFeatureNamesAsync ( )
29
+ public IAsyncEnumerable < string > GetFeatureNamesAsync ( )
30
+ {
31
+ return GetFeatureNamesAsync ( CancellationToken . None ) ;
32
+ }
33
+
34
+ public async IAsyncEnumerable < string > GetFeatureNamesAsync ( [ EnumeratorCancellation ] CancellationToken cancellationToken )
29
35
{
30
36
if ( _featureNames == null )
31
37
{
32
38
var featureNames = new List < string > ( ) ;
33
39
34
- await foreach ( string featureName in _featureManager . GetFeatureNamesAsync ( ) . ConfigureAwait ( false ) )
40
+ await foreach ( string featureName in _featureManager . GetFeatureNamesAsync ( cancellationToken ) . ConfigureAwait ( false ) )
35
41
{
36
42
featureNames . Add ( featureName ) ;
37
43
}
@@ -49,28 +55,28 @@ public Task<bool> IsEnabledAsync(string feature)
49
55
{
50
56
return _flagCache . GetOrAdd (
51
57
feature ,
52
- ( key ) => _featureManager . IsEnabledAsync ( key ) ) ;
58
+ ( key ) => _featureManager . IsEnabledAsync ( key , CancellationToken . None ) ) ;
53
59
}
54
60
55
61
public Task < bool > IsEnabledAsync < TContext > ( string feature , TContext context )
56
62
{
57
63
return _flagCache . GetOrAdd (
58
64
feature ,
59
- ( key ) => _featureManager . IsEnabledAsync ( key , context ) ) ;
65
+ ( key ) => _featureManager . IsEnabledAsync ( key , context , CancellationToken . None ) ) ;
60
66
}
61
67
62
68
public Task < bool > IsEnabledAsync ( string feature , CancellationToken cancellationToken )
63
69
{
64
70
return _flagCache . GetOrAdd (
65
71
feature ,
66
- ( key ) => _featureManager . IsEnabledAsync ( key ) ) ;
72
+ ( key ) => _featureManager . IsEnabledAsync ( key , cancellationToken ) ) ;
67
73
}
68
74
69
75
public Task < bool > IsEnabledAsync < TContext > ( string feature , TContext context , CancellationToken cancellationToken )
70
76
{
71
77
return _flagCache . GetOrAdd (
72
78
feature ,
73
- ( key ) => _featureManager . IsEnabledAsync ( key , context ) ) ;
79
+ ( key ) => _featureManager . IsEnabledAsync ( key , context , cancellationToken ) ) ;
74
80
}
75
81
76
82
public async ValueTask < Variant > GetVariantAsync ( string feature , CancellationToken cancellationToken )
0 commit comments