Skip to content

Commit

Permalink
Deprecate block waiting synchronous methods of IConfigCatClient
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Apr 15, 2024
1 parent 6f5579c commit cee428d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -23,9 +23,9 @@ public BackdoorController(IConfigCatClient configCatClient)
// This endpoint can be called by Configcat Webhooks https://configcat.com/docs/advanced/notifications-webhooks
[HttpGet]
[Route("configcatchanged")]
public IActionResult ConfigCatChanged()
public async Task<IActionResult> ConfigCatChanged()
{
this.configCatClient.ForceRefresh();
await this.configCatClient.ForceRefreshAsync();

return Ok("configCatClient.ForceRefresh() invoked");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using ConfigCat.Client;
using Microsoft.AspNetCore.Mvc;
using WebApplication.Models;
Expand All @@ -15,9 +15,9 @@ public HomeController(IConfigCatClient configCatClient)
this.configCatClient = configCatClient;
}

public IActionResult Index()
public async Task<IActionResult> Index()
{
ViewData["Message1"] = this.configCatClient.GetValue("isAwesomeFeatureEnabled", false);
ViewData["Message1"] = await this.configCatClient.GetValueAsync("isAwesomeFeatureEnabled", false);

var userObject = new User("<Some UserID>")
{
Expand All @@ -30,7 +30,7 @@ public IActionResult Index()
}
};

ViewData["Message2"] = this.configCatClient.GetValue("isPOCFeatureEnabled", false, userObject);
ViewData["Message2"] = await this.configCatClient.GetValueAsync("isPOCFeatureEnabled", false, userObject);

return View();
}
Expand Down
4 changes: 2 additions & 2 deletions samples/ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using ConfigCat.Client;

// Creating the ConfigCat client instance using the SDK Key
Expand All @@ -21,5 +21,5 @@
};

// Accessing feature flag or setting value
var value = client.GetValue("isPOCFeatureEnabled", false, user);
var value = await client.GetValueAsync("isPOCFeatureEnabled", false, user);
Console.WriteLine($"isPOCFeatureEnabled: {value}");
5 changes: 3 additions & 2 deletions samples/FileLoggerSample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using ConfigCat.Client;

namespace SampleApplication
Expand Down Expand Up @@ -56,7 +57,7 @@ public void Log(LogLevel level, LogEventId eventId, ref FormattableLogMessage me
}
}

static void Main(string[] args)
static async Task Main(string[] args)
{
var filePath = Path.Combine(Environment.CurrentDirectory, "configcat.log");
var logLevel = LogLevel.Warning; // Log only WARNING and higher entries (warnings and errors).
Expand All @@ -67,7 +68,7 @@ static void Main(string[] args)
options.PollingMode = PollingModes.AutoPoll(pollInterval: TimeSpan.FromSeconds(5));
});

var feature = client.GetValue("keyNotExists", "N/A");
var feature = await client.GetValueAsync("keyNotExists", "N/A");

Console.ReadKey();
}
Expand Down
1 change: 1 addition & 0 deletions src/ConfigCat.Client.Tests/ConfigCat.Client.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<NoWarn>CS0618</NoWarn>
<AssemblyOriginatorKeyFile>..\ConfigCatClient.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

Expand Down
6 changes: 6 additions & 0 deletions src/ConfigCatClient/ConfigCatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public static void DisposeAll()
}

/// <inheritdoc />
[Obsolete("This method may lead to an unresponsive application (see remarks), thus it will be removed from the public API in a future major version. Please use either the async version of the method or snaphots.")]
public T GetValue<T>(string key, T defaultValue, User? user = null)
{
if (key is null)
Expand Down Expand Up @@ -341,6 +342,7 @@ public async Task<T> GetValueAsync<T>(string key, T defaultValue, User? user = n
}

/// <inheritdoc />
[Obsolete("This method may lead to an unresponsive application (see remarks), thus it will be removed from the public API in a future major version. Please use either the async version of the method or snaphots.")]
public EvaluationDetails<T> GetValueDetails<T>(string key, T defaultValue, User? user = null)
{
if (key is null)
Expand Down Expand Up @@ -411,6 +413,7 @@ public async Task<EvaluationDetails<T>> GetValueDetailsAsync<T>(string key, T de
}

/// <inheritdoc />
[Obsolete("This method may lead to an unresponsive application (see remarks), thus it will be removed from the public API in a future major version. Please use either the async version of the method or snaphots.")]
public IReadOnlyCollection<string> GetAllKeys()
{
const string defaultReturnValue = "empty collection";
Expand Down Expand Up @@ -455,6 +458,7 @@ public async Task<IReadOnlyCollection<string>> GetAllKeysAsync(CancellationToken
}

/// <inheritdoc />
[Obsolete("This method may lead to an unresponsive application (see remarks), thus it will be removed from the public API in a future major version. Please use either the async version of the method or snaphots.")]
public IReadOnlyDictionary<string, object?> GetAllValues(User? user = null)
{
const string defaultReturnValue = "empty dictionary";
Expand Down Expand Up @@ -525,6 +529,7 @@ public async Task<IReadOnlyCollection<string>> GetAllKeysAsync(CancellationToken
}

/// <inheritdoc />
[Obsolete("This method may lead to an unresponsive application (see remarks), thus it will be removed from the public API in a future major version. Please use either the async version of the method or snaphots.")]
public IReadOnlyList<EvaluationDetails> GetAllValueDetails(User? user = null)
{
const string defaultReturnValue = "empty list";
Expand Down Expand Up @@ -591,6 +596,7 @@ public async Task<IReadOnlyList<EvaluationDetails>> GetAllValueDetailsAsync(User
}

/// <inheritdoc />
[Obsolete("This method may lead to an unresponsive application (see remarks), thus it will be removed from the public API in a future major version. Please use either the async version of the method or snaphots.")]
public RefreshResult ForceRefresh()
{
try
Expand Down
6 changes: 6 additions & 0 deletions src/ConfigCatClient/IConfigCatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public interface IConfigCatClient : IProvidesHooks, IDisposable
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="key"/> is an empty string.</exception>
/// <exception cref="ArgumentException"><typeparamref name="T"/> is not an allowed type.</exception>
[Obsolete("This method may lead to an unresponsive application (see remarks), thus it will be removed from the public API in a future major version. Please use either the async version of the method or snaphots.")]
T GetValue<T>(string key, T defaultValue, User? user = null);

/// <summary>
Expand Down Expand Up @@ -92,6 +93,7 @@ public interface IConfigCatClient : IProvidesHooks, IDisposable
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="key"/> is an empty string.</exception>
/// <exception cref="ArgumentException"><typeparamref name="T"/> is not an allowed type.</exception>
[Obsolete("This method may lead to an unresponsive application (see remarks), thus it will be removed from the public API in a future major version. Please use either the async version of the method or snaphots.")]
EvaluationDetails<T> GetValueDetails<T>(string key, T defaultValue, User? user = null);

/// <summary>
Expand Down Expand Up @@ -129,6 +131,7 @@ public interface IConfigCatClient : IProvidesHooks, IDisposable
/// </para>
/// </remarks>
/// <returns>The collection of keys.</returns>
[Obsolete("This method may lead to an unresponsive application (see remarks), thus it will be removed from the public API in a future major version. Please use either the async version of the method or snaphots.")]
IReadOnlyCollection<string> GetAllKeys();

/// <summary>
Expand All @@ -150,6 +153,7 @@ public interface IConfigCatClient : IProvidesHooks, IDisposable
/// </remarks>
/// <param name="user">The User Object to use for evaluating targeting rules and percentage options.</param>
/// <returns>The dictionary containing the keys and values.</returns>
[Obsolete("This method may lead to an unresponsive application (see remarks), thus it will be removed from the public API in a future major version. Please use either the async version of the method or snaphots.")]
IReadOnlyDictionary<string, object?> GetAllValues(User? user = null);

/// <summary>
Expand All @@ -172,6 +176,7 @@ public interface IConfigCatClient : IProvidesHooks, IDisposable
/// </remarks>
/// <param name="user">The User Object to use for evaluating targeting rules and percentage options.</param>
/// <returns>The list of values along with evaluation details.</returns>
[Obsolete("This method may lead to an unresponsive application (see remarks), thus it will be removed from the public API in a future major version. Please use either the async version of the method or snaphots.")]
IReadOnlyList<EvaluationDetails> GetAllValueDetails(User? user = null);

/// <summary>
Expand All @@ -193,6 +198,7 @@ public interface IConfigCatClient : IProvidesHooks, IDisposable
/// </para>
/// </remarks>
/// <returns>The refresh result.</returns>
[Obsolete("This method may lead to an unresponsive application (see remarks), thus it will be removed from the public API in a future major version. Please use either the async version of the method or snaphots.")]
RefreshResult ForceRefresh();

/// <summary>
Expand Down

0 comments on commit cee428d

Please sign in to comment.