Repository navigation
Conversation
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6-astra
Assisted-by: codex:gpt-6-astra
Assisted-by: codex:gpt-6-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
| /// Creates a task that waits for `future` and returns its result. Cancelling the task handle | ||
| /// does not cancel the future or interrupt a running wait. Future cancellation propagates | ||
| /// as a [CancellationException]. | ||
| public static <T extends @Nullable Object> Task<T> fromCompletableFuture(CompletableFuture<T> future) { |
There was a problem hiding this comment.
[ERROR] [com.puppycrawl.tools.checkstyle.checks.whitespace.SingleSpaceSeparatorCheck]
Use a single space to separate non-whitespace characters.
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
| import org.jackhuang.hmcl.task.DownloadException; | ||
| import org.jackhuang.hmcl.task.FileDownloadTask; | ||
| import org.jackhuang.hmcl.task.Task; | ||
| import org.jackhuang.hmcl.task.TaskExecutionContext; |
There was a problem hiding this comment.
[ERROR] [com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck]
Unused import - org.jackhuang.hmcl.task.TaskExecutionContext.
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.junit.jupiter.api.Assertions.fail; |
There was a problem hiding this comment.
[ERROR] [com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck]
Unused import - org.junit.jupiter.api.Assertions.fail.
Assisted-by: codex:gpt-6.2-astra
| import org.jackhuang.hmcl.task.DownloadException; | ||
| import org.jackhuang.hmcl.task.FileDownloadTask; | ||
| import org.jackhuang.hmcl.task.Task; | ||
| import org.jackhuang.hmcl.task.TaskExecutionContext; |
There was a problem hiding this comment.
[ERROR] [com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck]
Unused import - org.jackhuang.hmcl.task.TaskExecutionContext.
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.junit.jupiter.api.Assertions.fail; |
There was a problem hiding this comment.
[ERROR] [com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck]
Unused import - org.junit.jupiter.api.Assertions.fail.
Assisted-by: codex:gpt-6.2-astra
| import org.jackhuang.hmcl.task.DownloadException; | ||
| import org.jackhuang.hmcl.task.FileDownloadTask; | ||
| import org.jackhuang.hmcl.task.Task; | ||
| import org.jackhuang.hmcl.task.TaskExecutionContext; |
There was a problem hiding this comment.
[ERROR] [com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck]
Unused import - org.jackhuang.hmcl.task.TaskExecutionContext.
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.junit.jupiter.api.Assertions.fail; |
There was a problem hiding this comment.
[ERROR] [com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck]
Unused import - org.junit.jupiter.api.Assertions.fail.
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
Assisted-by: codex:gpt-6.2-astra
在 HMCL 中,
Task是异步任务的核心抽象。但是过去TaskAPI 设计极其复杂与混乱,存在诸多问题:Task的 API 使用了一套声明式回调模型,而且在开发过程中不断为了需求添加新 API,又缺乏文档,导致整个TaskAPI 过度复杂。Task API 的使用者需要了解
preExecute/dependents/postExecute/dependencies等几个执行阶段的先后顺序和依赖关系,再了解isRelyingOnDependents()、isRelyingOnDependencies()、isDependentsSucceeded()、isDependenciesSucceeded()等 API,这样才能明白Task的执行模型。这套复杂的模型也导致使用 Task API 时很难完善的管理好资源,容易产生资源泄露现象。
Task对象过于庞大,而且内部还有多个 JavaFX Property,导致和 JavaFX 产生了不必要的耦合。Task有一套和CompletionFuture较为接近的 API,但存在大量微妙的语义差别,导致开发者和 AI 都容易产生混淆。Task的调度机制复杂且沉重,即便是很简单的任务,底层的AsyncTaskExecutor也会翻译成多个CompletionFuture,开销很高。本 PR 重构了
Task相关的 API,大幅简化了 API 设计,优化了调度性能,使Task更容易开发、阅读、维护。