small fix on task.finish

This commit is contained in:
yusing 2025-01-01 06:16:33 +08:00
parent 4dda54c9e6
commit 846c1a104e

View file

@ -93,15 +93,10 @@ func (t *Task) onCancel(about string, fn func(), waitSubTasks bool) {
// Finish cancel all subtasks and wait for them to finish,
// then marks the task as finished, with the given reason (if any).
func (t *Task) Finish(reason any) {
select {
case <-t.finished:
return
default:
t.once.Do(func() {
t.finish(reason)
})
}
}
func (t *Task) finish(reason any) {
t.cancel(fmtCause(reason))