Skip to content

Commit

Permalink
Fix cleanup.
Browse files Browse the repository at this point in the history
Signed-off-by: André Silva <[email protected]>
  • Loading branch information
askpt committed Dec 4, 2024
1 parent 39b3e9c commit 35b90bf
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/OpenFeature/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ private Api() { }
public async Task SetProviderAsync(FeatureProvider featureProvider)
{
this._eventExecutor.RegisterDefaultFeatureProvider(featureProvider);
await this._repository
.SetProviderAsync(featureProvider, this.GetContext(), this.AfterInitialization, this.AfterError)
.ConfigureAwait(false);
await this._repository.SetProviderAsync(featureProvider, this.GetContext(), this.AfterInitialization, this.AfterError).ConfigureAwait(false);

}

/// <summary>
Expand All @@ -65,11 +64,8 @@ public async Task SetProviderAsync(string domain, FeatureProvider featureProvide
{
throw new ArgumentNullException(nameof(domain));
}

this._eventExecutor.RegisterClientFeatureProvider(domain, featureProvider);
await this._repository
.SetProviderAsync(domain, featureProvider, this.GetContext(), this.AfterInitialization, this.AfterError)
.ConfigureAwait(false);
await this._repository.SetProviderAsync(domain, featureProvider, this.GetContext(), this.AfterInitialization, this.AfterError).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -345,27 +341,23 @@ private async Task AfterInitialization(FeatureProvider provider)
ProviderName = provider.GetMetadata()?.Name,
};

await this._eventExecutor.EventChannel.Writer
.WriteAsync(new Event { Provider = provider, EventPayload = eventPayload }).ConfigureAwait(false);
await this._eventExecutor.EventChannel.Writer.WriteAsync(new Event { Provider = provider, EventPayload = eventPayload }).ConfigureAwait(false);
}

/// <summary>
/// Update the provider state to ERROR and emit an ERROR after failed init.
/// </summary>
private async Task AfterError(FeatureProvider provider, Exception? ex)
{
provider.Status = typeof(ProviderFatalException) == ex?.GetType()
? ProviderStatus.Fatal
: ProviderStatus.Error;
provider.Status = typeof(ProviderFatalException) == ex?.GetType() ? ProviderStatus.Fatal : ProviderStatus.Error;
var eventPayload = new ProviderEventPayload
{
Type = ProviderEventTypes.ProviderError,
Message = $"Provider initialization error: {ex?.Message}",
ProviderName = provider.GetMetadata()?.Name,
};

await this._eventExecutor.EventChannel.Writer
.WriteAsync(new Event { Provider = provider, EventPayload = eventPayload }).ConfigureAwait(false);
await this._eventExecutor.EventChannel.Writer.WriteAsync(new Event { Provider = provider, EventPayload = eventPayload }).ConfigureAwait(false);
}
}
}

0 comments on commit 35b90bf

Please sign in to comment.