(ctx context.Context, groupID string, success bool)
| 55 | } |
| 56 | |
| 57 | func (tgc *TaskGroupCoordinator) Done(ctx context.Context, groupID string, success bool) { |
| 58 | tgc.mu.Lock() |
| 59 | defer tgc.mu.Unlock() |
| 60 | state, ok := tgc.groupStates[groupID] |
| 61 | if !ok || state.pending == 0 { |
| 62 | return |
| 63 | } |
| 64 | if success { |
| 65 | state.hasSuccess = true |
| 66 | } |
| 67 | logrus.Debugf("Done:%s ,state=%+v", groupID, state) |
| 68 | if state.pending == 1 { |
| 69 | payloads := tgc.groupPayloads[groupID] |
| 70 | delete(tgc.groupStates, groupID) |
| 71 | delete(tgc.groupPayloads, groupID) |
| 72 | if tgc.onCompletion != nil && state.hasSuccess { |
| 73 | logrus.Debugf("OnCompletion:%s", groupID) |
| 74 | tgc.mu.Unlock() |
| 75 | tgc.onCompletion(ctx, groupID, payloads...) |
| 76 | tgc.mu.Lock() |
| 77 | } |
| 78 | return |
| 79 | } |
| 80 | state.pending-- |
| 81 | tgc.groupStates[groupID] = state |
| 82 | } |
no test coverage detected