func readSuites()

in pkg/updater/read.go [543:594]


func readSuites(parent context.Context, client gcs.Downloader, build gcs.Build) ([]gcs.SuitesMeta, error) {
	ctx, cancel := context.WithCancel(parent)
	defer cancel()
	ec := make(chan error)

	// List
	artifacts := make(chan string, 1)
	go func() {
		defer close(artifacts) // No more artifacts
		if err := build.Artifacts(ctx, client, artifacts); err != nil {
			select {
			case <-ctx.Done():
			case ec <- fmt.Errorf("list: %w", err):
			}
		}
	}()

	// Download
	suitesChan := make(chan gcs.SuitesMeta, 1)
	go func() {
		defer close(suitesChan) // No more rows
		const max = 1000
		if err := build.Suites(ctx, client, artifacts, suitesChan, max); err != nil {
			select {
			case <-ctx.Done():
			case ec <- fmt.Errorf("download: %w", err):
			}
		}
	}()

	// Append
	var suites []gcs.SuitesMeta
	go func() {
		for suite := range suitesChan {
			suites = append(suites, suite)
		}
		select {
		case <-ctx.Done():
		case ec <- nil:
		}
	}()

	select {
	case <-ctx.Done():
		return nil, ctx.Err()
	case err := <-ec:
		if err != nil {
			return nil, err
		}
	}
	return suites, nil
}