Skip to content

Commit

Permalink
Common: Fix race condition during completion of recurrent task
Browse files Browse the repository at this point in the history
Issue #13
  • Loading branch information
xuhcc committed Jun 26, 2021
1 parent b794919 commit 42c331b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.6.1

- Mobile, Web: Fix task duplication during completion of recurrent task.
- Mobile: Upgraded datepicker plugin.
- Mobile, Web: Upgraded jsTodoTxt to version 0.10.0.
- Web: Fixed styles for chrome browser.
Expand Down
16 changes: 12 additions & 4 deletions src/app/task-list/task-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,21 @@ export class TaskListComponent implements OnInit, OnDestroy {
this.postponeTask(task)
return
}
let recurDone: Promise<void>
if (task.due && task.rec && !task.completed) {
// Create a copy if task is recurrent
// and wait for append operation to complete
const newTask = task.recur()
this.todoFile.appendTask(newTask)
recurDone = this.todoFile.appendTask(newTask)
} else {
// Otherwise resolve immediately
recurDone = Promise.resolve()
}
task.toggleComplete()
this.refreshTaskList()
this.todoFile.replaceTask(task.id, task)
recurDone.then(() => {
task.toggleComplete()
this.refreshTaskList()
this.todoFile.replaceTask(task.id, task)
})
}

postponeTask(task: Task) {
Expand Down

0 comments on commit 42c331b

Please sign in to comment.