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, // Finish cancel all subtasks and wait for them to finish,
// then marks the task as finished, with the given reason (if any). // then marks the task as finished, with the given reason (if any).
func (t *Task) Finish(reason any) { func (t *Task) Finish(reason any) {
select {
case <-t.finished:
return
default:
t.once.Do(func() { t.once.Do(func() {
t.finish(reason) t.finish(reason)
}) })
} }
}
func (t *Task) finish(reason any) { func (t *Task) finish(reason any) {
t.cancel(fmtCause(reason)) t.cancel(fmtCause(reason))