This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make #updatePresence use ScheduledThreadPool to try to avoid crashing.
This tries to resolve the issue of presence updates not occurring as they should after about 6000 rounds, which sounds suspiciously like a stack overflow. (#21)
- Loading branch information
Showing
2 changed files
with
52 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
modules/bot/src/main/kotlin/dev/proxyfox/bot/SchedulerUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2022, The ProxyFox Group | ||
* | ||
* This Source Code is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package dev.proxyfox.bot | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import java.util.concurrent.ScheduledExecutorService | ||
import java.util.concurrent.TimeUnit | ||
import kotlin.time.Duration | ||
|
||
// Created 2022-08-12T16:06:42 | ||
|
||
/** | ||
* Helper functions for [ScheduledExecutorService]. | ||
* | ||
* @author Ampflower | ||
* @since 2.0.8 | ||
**/ | ||
|
||
/** | ||
* Wrapper around [ScheduledExecutorService.scheduleAtFixedRate] to provide a Kotlin Coroutine equivalent. | ||
* | ||
* @param initialDelay The initial delay. Will be treated as milliseconds. | ||
* @param period The period in which future action runs will occur. Will be treated as milliseconds. | ||
* @param action The action to execute within a coroutine scope. | ||
* */ | ||
fun ScheduledExecutorService.fixedRateAction(initialDelay: Duration, period: Duration, action: suspend CoroutineScope.() -> Unit) { | ||
scheduleAtFixedRate({ | ||
scope.launch(block = action) | ||
}, initialDelay.inWholeMilliseconds, period.inWholeMilliseconds, TimeUnit.MILLISECONDS) | ||
} |