Skip to content

Commit

Permalink
Use ThreadLocal instead of AsyncLocal + remove async for quick & dirt…
Browse files Browse the repository at this point in the history
…y fix
  • Loading branch information
maxisoft committed Dec 3, 2024
1 parent a5dd91b commit c42f356
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ASFFreeGames/ASFFreeGamesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal static PluginContext Context {
}

// ReSharper disable once InconsistentNaming
private static readonly AsyncLocal<PluginContext> _context = new();
private static readonly ThreadLocal<PluginContext> _context = new();
private static CancellationToken CancellationToken => Context.CancellationToken;

public string Name => StaticName;
Expand Down Expand Up @@ -107,7 +107,7 @@ public async Task OnASFInit(IReadOnlyDictionary<string, JsonElement>? additional

public Task OnUpdateProceeding(Version currentVersion, Version newVersion) => Task.CompletedTask;

public async void CollectGamesOnClock(object? source) {
public void CollectGamesOnClock(object? source) {
CollectIntervalManager.RandomlyChangeCollectInterval(source);

if (!Context.Valid || ((Bots.Count > 0) && (Context.Bots.Count != Bots.Count))) {
Expand Down Expand Up @@ -141,7 +141,9 @@ public async void CollectGamesOnClock(object? source) {

if (!cts.IsCancellationRequested) {
string cmd = $"FREEGAMES {FreeGamesCommand.CollectInternalCommandString} " + string.Join(' ', reorderedBots.Select(static bot => bot.BotName));
await OnBotCommand(null!, EAccess.None, cmd, cmd.Split()).ConfigureAwait(false);
#pragma warning disable CS1998
OnBotCommand(null!, EAccess.None, cmd, cmd.Split()).GetAwaiter().GetResult(); // TODO use async
#pragma warning restore CS1998
}
}
}
Expand Down

0 comments on commit c42f356

Please sign in to comment.