agent/utils/sync/sequential_waitgroup.go
func (s *SequentialWaitGroup) Wait(sequence int64) {
	waitOver := func() bool {
		s.mutex.Lock()
		defer s.mutex.Unlock()
		for storedSequence := range s.semaphores {
			if storedSequence <= sequence {
				// At least one non-empty seqnum greater than ours; wait more
				return false
			}
		}
		return true
	}

	s.change.L.Lock()
	defer s.change.L.Unlock()
	// Wake up to check if our wait is over after each element being deleted from the map
	for !waitOver() {
		s.change.Wait()
	}
}
func (s *SequentialWaitGroup) Wait(sequence int64) {
	waitOver := func() bool {
		s.mutex.Lock()
		defer s.mutex.Unlock()
		for storedSequence := range s.semaphores {
			if storedSequence <= sequence {
				// At least one non-empty seqnum greater than ours; wait more
				return false
			}
		}
		return true
	}

	s.change.L.Lock()
	defer s.change.L.Unlock()
	// Wake up to check if our wait is over after each element being deleted from the map
	for !waitOver() {
		s.change.Wait()
	}
}
// Wait waits for all waitgroups at or below the given sequence to complete.
// Please note that this is *INCLUSIVE* of the sequence