func verifyCasesConcurrently()

in commands/verify/verify.go [147:180]


func verifyCasesConcurrently(verify *config.Verify, verifyInfo *verifyInfo) error {
	res := make([]*output.CaseResult, len(verify.Cases))
	for i := range res {
		res[i] = &output.CaseResult{}
	}
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	var wg sync.WaitGroup
	for idx := range verify.Cases {
		wg.Add(1)
		go func(i int) {
			defer wg.Done()

			// Check if the context is canceled before verifying the case.
			select {
			case <-ctx.Done():
				res[i].Skip = true
				return
			default:
				// It's safe to do this, since each goroutine only modifies a single, different, designated slice element.
				res[i] = concurrentlyVerifySingleCase(ctx, cancel, &verify.Cases[i], verifyInfo)
			}
		}(idx)
	}
	wg.Wait()

	_, errNum, _ := printer.PrintResult(res)
	if errNum > 0 {
		return fmt.Errorf("failed to verify %d case(s)", errNum)
	}

	return nil
}