Skip to content

Commit

Permalink
Merge pull request #3 from FFFabulousRobotics/task-concept
Browse files Browse the repository at this point in the history
Fix the wrong calling timing of task.init()
  • Loading branch information
LeChocolatChaud authored Sep 17, 2024
2 parents 19d33f9 + 56eab54 commit 7b88b25
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Android CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public void runOpMode() {
task.finish();
tasks.remove(taskId, task);
taskLinks.remove(taskId);
taskLinks.entrySet().stream()
.filter(e -> e.getValue() == taskId)
.forEach(e -> tasks.get(e).init());
continue;
}
Integer linkedTaskId = taskLinks.get(taskId);
Expand All @@ -56,6 +59,7 @@ public void runOpMode() {
}

public int registerTask(Task task) {
task.init();
return registerTask(task, -1);
}

Expand All @@ -70,7 +74,6 @@ public int registerTask(Task task) {
* @return the taskId of the registered task.
*/
public int registerTask(Task task, int linkedTaskId) {
task.init();
int taskId = findMinFreeTaskId();
tasks.put(taskId, task);
taskLinks.put(taskId, linkedTaskId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface Task {
boolean hasNext();

/**
* This method is called when the task is registered in the TaskOpMode.
* This method is called once when the task starts looping in the TaskOpMode.
*/
default void init() {
}
Expand Down

0 comments on commit 7b88b25

Please sign in to comment.