-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: use (and require) OpenFeature SDK v2 #262
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using ConfigCat.Client; | ||
using ConfigCat.Client.Configuration; | ||
|
@@ -35,34 +36,34 @@ public override Metadata GetMetadata() | |
} | ||
|
||
/// <inheritdoc/> | ||
public override Task<ResolutionDetails<bool>> ResolveBooleanValue(string flagKey, bool defaultValue, EvaluationContext context = null) | ||
public override Task<ResolutionDetails<bool>> ResolveBooleanValueAsync(string flagKey, bool defaultValue, EvaluationContext context = null, CancellationToken cancellationToken = default) | ||
{ | ||
return ResolveFlag(flagKey, context, defaultValue); | ||
return ResolveFlag(flagKey, context, defaultValue, cancellationToken); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override Task<ResolutionDetails<string>> ResolveStringValue(string flagKey, string defaultValue, EvaluationContext context = null) | ||
public override Task<ResolutionDetails<string>> ResolveStringValueAsync(string flagKey, string defaultValue, EvaluationContext context = null, CancellationToken cancellationToken = default) | ||
{ | ||
return ResolveFlag(flagKey, context, defaultValue); | ||
return ResolveFlag(flagKey, context, defaultValue, cancellationToken); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override Task<ResolutionDetails<int>> ResolveIntegerValue(string flagKey, int defaultValue, EvaluationContext context = null) | ||
public override Task<ResolutionDetails<int>> ResolveIntegerValueAsync(string flagKey, int defaultValue, EvaluationContext context = null, CancellationToken cancellationToken = default) | ||
{ | ||
return ResolveFlag(flagKey, context, defaultValue); | ||
return ResolveFlag(flagKey, context, defaultValue, cancellationToken); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override Task<ResolutionDetails<double>> ResolveDoubleValue(string flagKey, double defaultValue, EvaluationContext context = null) | ||
public override Task<ResolutionDetails<double>> ResolveDoubleValueAsync(string flagKey, double defaultValue, EvaluationContext context = null, CancellationToken cancellationToken = default) | ||
{ | ||
return ResolveFlag(flagKey, context, defaultValue); | ||
return ResolveFlag(flagKey, context, defaultValue, cancellationToken); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override async Task<ResolutionDetails<Value>> ResolveStructureValue(string flagKey, Value defaultValue, EvaluationContext context = null) | ||
public override async Task<ResolutionDetails<Value>> ResolveStructureValueAsync(string flagKey, Value defaultValue, EvaluationContext context = null, CancellationToken cancellationToken = default) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't want to really make any functional changes here, but this was a very easy one since the ConfigCat SDK already accepted a cancellation token, so I've done this. |
||
{ | ||
var user = context?.BuildUser(); | ||
var result = await Client.GetValueDetailsAsync(flagKey, defaultValue?.AsObject, user); | ||
var result = await Client.GetValueDetailsAsync(flagKey, defaultValue?.AsObject, user, cancellationToken); | ||
var returnValue = result.IsDefaultValue ? defaultValue : new Value(result.Value); | ||
var details = new ResolutionDetails<Value>(flagKey, returnValue, TranslateErrorCode(result.ErrorCode), errorMessage: result.ErrorMessage, variant: result.VariationId); | ||
if (details.ErrorType == ErrorType.None) | ||
|
@@ -73,10 +74,10 @@ public override async Task<ResolutionDetails<Value>> ResolveStructureValue(strin | |
throw new FeatureProviderException(details.ErrorType, details.ErrorMessage); | ||
} | ||
|
||
private async Task<ResolutionDetails<T>> ResolveFlag<T>(string flagKey, EvaluationContext context, T defaultValue) | ||
private async Task<ResolutionDetails<T>> ResolveFlag<T>(string flagKey, EvaluationContext context, T defaultValue, CancellationToken cancellationToken) | ||
{ | ||
var user = context?.BuildUser(); | ||
var result = await Client.GetValueDetailsAsync(flagKey, defaultValue, user); | ||
var result = await Client.GetValueDetailsAsync(flagKey, defaultValue, user, cancellationToken); | ||
var details = new ResolutionDetails<T>(flagKey, result.Value, TranslateErrorCode(result.ErrorCode), errorMessage: result.ErrorMessage, variant: result.VariationId); | ||
if (details.ErrorType == ErrorType.None) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've set this to only major version 2 up to 3 (exclusive).