Skip to content

Commit

Permalink
Limit number of running booster queue tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Citrinate committed Jun 5, 2024
1 parent c009932 commit 77ca468
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions BoosterManager/Boosters/BoosterQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal sealed class BoosterQueue {
private const int BoosterInfosUpdateBackOffMaxMinutes = 15;
private float BoosterInfosUpdateBackOffMultiplier = BoosterInfosUpdateBackOffMultiplierDefault;
private SemaphoreSlim RunSemaphore = new SemaphoreSlim(1, 1);
private bool RunScheduled = false;

internal BoosterQueue(Bot bot) {
Bot = bot;
Expand All @@ -42,8 +43,21 @@ internal void Start() {
}

private async Task Run() {
// Allow for a maximum of two running tasks, one waiting, and one working
lock (RunSemaphore) {
if (RunScheduled) {
return;
}

RunScheduled = true;
}

await RunSemaphore.WaitAsync().ConfigureAwait(false);
try {
lock (RunSemaphore) {
RunScheduled = false;
}

if (!Bot.IsConnectedAndLoggedOn) {
UpdateTimer(DateTime.Now.AddSeconds(1));

Expand Down

0 comments on commit 77ca468

Please sign in to comment.