Skip to content

Commit

Permalink
fix: make sure DataFetcher only runs once at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
My-Name-Is-Jeff committed May 16, 2024
1 parent 205edae commit 6735825
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/main/kotlin/gg/skytils/skytilsmod/core/DataFetcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import kotlin.concurrent.fixedRateTimer
import kotlin.reflect.jvm.jvmName

object DataFetcher {
private var job: Job? = null

private fun loadData(): Job {
return Skytils.IO.launch {
try {
Expand Down Expand Up @@ -213,8 +215,13 @@ object DataFetcher {
}

@JvmStatic
fun reloadData() =
loadData()
fun reloadData() {
if (job?.isActive != true) {
job = loadData()
} else {
UChat.chat("$failPrefix §cData fetch requested while already fetching!")
}
}

internal fun preload() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.utils.io.jvm.javaio.*
import kotlinx.coroutines.launch
import java.util.concurrent.ConcurrentHashMap
import javax.imageio.ImageIO

object SummonSkins {
// maps name to url
val skinMap = HashMap<String, String>()
val skinMap = ConcurrentHashMap<String, String>()

// maps name to dynamic resource
val skintextureMap = HashMap<String, DynamicResource>()
Expand Down

0 comments on commit 6735825

Please sign in to comment.