Skip to content

Adds cancellationtoken to the FeatureEvaluationContext- and respects … #532

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rossgrambo
Copy link
Contributor

This pull request introduces a cancellation mechanism to the feature evaluation process in the Microsoft.FeatureManagement library. The changes ensure that long-running feature evaluations can be cancelled if needed, improving the responsiveness and control over feature management operations.

Key changes include:

Cancellation Token Integration:

Cancellation Checks:

These updates enhance the robustness of the feature management system by allowing operations to be cancelled gracefully, which can be particularly useful in scenarios where feature evaluations are time-sensitive or resource-intensive.

Addresses #531

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a cancellation mechanism to the feature evaluation process in the Microsoft.FeatureManagement library, allowing for early termination during long-running feature evaluations.

  • Added a CancellationToken property to FeatureFilterEvaluationContext.
  • Integrated cancellation checks into the IsEnabledAsync and AssignVariantAsync methods to handle cancellation requests efficiently.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Microsoft.FeatureManagement/FeatureManager.cs Added cancellation checks in evaluation loops for feature enabled and variant assignment methods.
src/Microsoft.FeatureManagement/FeatureFilterEvaluationContext.cs Added a CancellationToken property to support cancellation in feature filters.

@@ -472,6 +472,11 @@ private async ValueTask<bool> IsEnabledAsync<TContext>(FeatureDefinition feature
// For all enabling filters listed in the feature's state, evaluate them according to requirement type
foreach (FeatureFilterConfiguration featureFilterConfiguration in featureDefinition.EnabledFor)
{
if (cancellationToken.IsCancellationRequested)
{
cancellationToken.ThrowIfCancellationRequested();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The surrounding if statement isn't needed. Note the If in the method name.

/// <summary>
/// A cancellation token that can be used to request cancellation of the feature evaluation operation.
/// </summary>
public CancellationToken CancellationToken { get; set; } = CancellationToken.None;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a struct, no need for an initializer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants