chore: enhance tasks debuggability

This commit is contained in:
yusing
2025-04-14 06:30:16 +08:00
parent 53a78706e4
commit 57da345335
2 changed files with 14 additions and 17 deletions

View File

@@ -45,7 +45,8 @@ type (
callbacks map[*Callback]struct{}
callbacksDone chan struct{}
finished chan struct{}
needFinish bool
finished chan struct{}
// finishedCalled == 1 Finish has been called
// but does not mean that the task is finished yet
// this is used to avoid calling Finish twice
@@ -145,10 +146,11 @@ func (t *Task) Subtask(name string, needFinish ...bool) *Task {
ctx, cancel := context.WithCancelCause(t.ctx)
child := &Task{
parent: t,
finished: make(chan struct{}),
ctx: ctx,
cancel: cancel,
parent: t,
needFinish: nf,
finished: make(chan struct{}),
ctx: ctx,
cancel: cancel,
}
if t != root {
child.name = t.name + "." + name