Skip to content

Commit 2f9040b

Browse files
committed
fix: ConfigFactory.kt
1 parent 860c6b8 commit 2f9040b

File tree

1 file changed

+5
-7
lines changed
  • plugin-shared/src/main/kotlin/app/simplecloud/plugin/api/shared/config

1 file changed

+5
-7
lines changed

plugin-shared/src/main/kotlin/app/simplecloud/plugin/api/shared/config/ConfigFactory.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class ConfigFactory(
4242
} else {
4343
createDefaultConfig(defaultConfig)
4444
}
45-
startWatching()
45+
46+
registerWatcher()
4647
}
4748

4849
private fun createDefaultConfig(defaultConfig: Any) {
@@ -71,15 +72,15 @@ class ConfigFactory(
7172
}
7273
}
7374

74-
private fun startWatching() {
75+
private fun registerWatcher(): Job {
7576
val watchService = FileSystems.getDefault().newWatchService()
7677
path.parent?.register(
7778
watchService,
7879
StandardWatchEventKinds.ENTRY_CREATE,
7980
StandardWatchEventKinds.ENTRY_MODIFY
8081
)
8182

82-
watchJob = CoroutineScope(coroutineContext).launch {
83+
return CoroutineScope(coroutineContext).launch {
8384
watchService.use { watchService ->
8485
while (isActive) {
8586
val key = watchService.take()
@@ -91,12 +92,9 @@ class ConfigFactory(
9192
}
9293
}
9394
}
94-
}
95+
}.also { watchJob = it }
9596
}
9697

97-
/**
98-
* Handles a single watch event.
99-
*/
10098
private suspend fun handleWatchEvent(event: WatchEvent<*>) {
10199
val path = event.context() as? Path ?: return
102100
if (!file.name.contains(path.toString())) return

0 commit comments

Comments
 (0)