Skip to content

Commit 36d975f

Browse files
committed
Added Dokka
1 parent 2073f38 commit 36d975f

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ val yarnMappings = project.properties["yarn_mappings"].toString()
99

1010
plugins {
1111
kotlin("jvm") version ("1.9.22")
12+
id("org.jetbrains.dokka") version "1.9.20"
1213
id("architectury-plugin") version "3.4-SNAPSHOT"
1314
id("dev.architectury.loom") version "1.5-SNAPSHOT" apply false
1415
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
@@ -20,6 +21,7 @@ architectury {
2021

2122
subprojects {
2223
apply(plugin = "dev.architectury.loom")
24+
apply(plugin = "org.jetbrains.dokka")
2325
dependencies {
2426
"minecraft"("com.mojang:minecraft:$minecraftVersion")
2527
"mappings"("net.fabricmc:yarn:$yarnMappings:v2")

common/src/main/kotlin/com/lambda/event/listener/SafeListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SafeListener(
1717
// if (!mc.isOnThread) {
1818
// LOG.warn("""
1919
// Event ${this::class.simpleName} executed outside the game thread.
20-
// This can lead to race conditions when manipulating game data.
20+
// This can lead to race conditions when manipulating shared data.
2121
// Consider moving the execution to the game thread using runSafeOnGameThread { ... } or runOnGameThread { ... }.
2222
// """.trimIndent())
2323
// }

common/src/main/kotlin/com/lambda/task/Task.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ abstract class Task<Result>(
6666
abstract suspend fun SafeContext.onAction(): Result
6767

6868
/**
69-
* This function is called when the task is cancelled.
69+
* This function is called when the task is canceled.
7070
* It should be overridden for tasks that need to perform cleanup operations,
7171
* such as cancelling a block breaking progress, releasing resources,
7272
* or stopping any ongoing operations that were started by the task.
@@ -107,41 +107,42 @@ abstract class Task<Result>(
107107

108108
if (iteration == repeats) {
109109
onSuccess(result)
110-
stopListening()
110+
tidyUp()
111111
return TaskResult.Success(result)
112112
}
113113

114114
onRepeat(iteration)
115115
}
116-
} catch (e: CancellationException) {
117-
stopListening()
118-
LOG.warn("Coroutine for task $name cancelled")
119-
runSafe {
120-
onCancel()
121-
}
122-
return TaskResult.Cancelled
123116
} catch (e: TimeoutCancellationException) {
124117
attempt++
125118
LOG.warn("Task $name timed out after $age ms and $attempt attempts")
126119
onRetry()
127-
stopListening()
120+
tidyUp()
121+
} catch (e: CancellationException) {
122+
tidyUp()
123+
LOG.warn("Coroutine for task $name cancelled")
124+
return TaskResult.Cancelled
128125
} catch (e: Throwable) {
129126
attempt++
130127
LOG.error("Task $name failed after $age ms and $attempt attempts", e)
131128
onException(e)
132-
stopListening()
129+
tidyUp()
133130
return TaskResult.Failure(e)
134131
}
135132

136-
stopListening()
133+
tidyUp()
137134
} while (attempt < maxAttempts || iteration <= repeats)
138135

139136
LOG.error("Task $name fully timed out after $age ms and $attempt attempts")
140137
onTimeout()
141138
return TaskResult.Timeout(timeout, attempt)
142139
}
143140

144-
private fun stopListening() {
141+
private fun tidyUp() {
142+
runSafe {
143+
onCancel()
144+
}
145+
145146
EventFlow.syncListeners.unsubscribe(syncListeners)
146147
EventFlow.concurrentListeners.unsubscribe(concurrentListeners)
147148

0 commit comments

Comments
 (0)