From dc27b0c8aa87462cd89a3380cd9b6404a94b4f54 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 3 Jan 2024 10:26:26 +0100 Subject: [PATCH] use WriteAsync to write to channel Signed-off-by: Florian Bacher --- src/OpenFeature/EventExecutor.cs | 6 +++--- test/OpenFeature.Tests/OpenFeatureEventTests.cs | 3 +++ test/OpenFeature.Tests/TestImplementations.cs | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/OpenFeature/EventExecutor.cs b/src/OpenFeature/EventExecutor.cs index dd1dea64..460c5dfc 100644 --- a/src/OpenFeature/EventExecutor.cs +++ b/src/OpenFeature/EventExecutor.cs @@ -137,7 +137,7 @@ private void StartListeningAndShutdownOld(FeatureProviderReference newProvider, var channel = oldProvider.Provider.GetEventChannel(); if (channel != null) { - channel.Writer.TryWrite(new ShutdownSignal()); + channel.Writer.WriteAsync(new ShutdownSignal()); } } } @@ -205,7 +205,7 @@ private async Task ProcessFeatureProviderEventsAsync(FeatureProviderReference pr switch (item) { case ProviderEventPayload eventPayload: - this.EventChannel.Writer.TryWrite(new Event { Provider = providerRef, EventPayload = eventPayload }); + this.EventChannel.Writer.WriteAsync(new Event { Provider = providerRef, EventPayload = eventPayload }); break; case ShutdownSignal _: providerRef.ShutdownSemaphore.Release(); @@ -264,7 +264,7 @@ private async Task ProcessEventAsync() public async Task SignalShutdownAsync() { // Enqueue a shutdown signal - this.EventChannel.Writer.TryWrite(new ShutdownSignal()); + this.EventChannel.Writer.WriteAsync(new ShutdownSignal()); // Wait for the processing loop to acknowledge the shutdown await this._shutdownSemaphore.WaitAsync().ConfigureAwait(false); diff --git a/test/OpenFeature.Tests/OpenFeatureEventTests.cs b/test/OpenFeature.Tests/OpenFeatureEventTests.cs index d4224474..3eb21b3a 100644 --- a/test/OpenFeature.Tests/OpenFeatureEventTests.cs +++ b/test/OpenFeature.Tests/OpenFeatureEventTests.cs @@ -51,6 +51,9 @@ public async Task API_Level_Event_Handlers_Should_Be_Registered() eventHandler.Invoke(Arg.Any()); Api.Instance.AddHandler(ProviderEventTypes.ProviderReady, eventHandler); + Api.Instance.AddHandler(ProviderEventTypes.ProviderConfigurationChanged, eventHandler); + Api.Instance.AddHandler(ProviderEventTypes.ProviderError, eventHandler); + Api.Instance.AddHandler(ProviderEventTypes.ProviderStale, eventHandler); var testProvider = new TestProvider(); await Api.Instance.SetProvider(testProvider); diff --git a/test/OpenFeature.Tests/TestImplementations.cs b/test/OpenFeature.Tests/TestImplementations.cs index 46be5d00..4ca40213 100644 --- a/test/OpenFeature.Tests/TestImplementations.cs +++ b/test/OpenFeature.Tests/TestImplementations.cs @@ -90,13 +90,13 @@ public override ProviderStatus GetStatus() public override Task Initialize(EvaluationContext context) { this._status = ProviderStatus.Ready; - this.EventChannel.Writer.TryWrite(new ProviderEventPayload { Type = ProviderEventTypes.ProviderReady, ProviderName = this.GetMetadata().Name }); + this.EventChannel.Writer.WriteAsync(new ProviderEventPayload { Type = ProviderEventTypes.ProviderReady, ProviderName = this.GetMetadata().Name }); return base.Initialize(context); } internal void SendEvent(ProviderEventTypes eventType) { - this.EventChannel.Writer.TryWrite(new ProviderEventPayload { Type = eventType, ProviderName = this.GetMetadata().Name }); + this.EventChannel.Writer.WriteAsync(new ProviderEventPayload { Type = eventType, ProviderName = this.GetMetadata().Name }); } } }