func()

in src/statequery/reservations.go [30:64]


func (state *State) RetrieveReservations(ctx context.Context, project string, locations []string) error {
	state.Reservations = make(map[string]Reservation)

	// Create shared BQ reservations client
	client, err := reservationSDK.NewClient(ctx)
	if err != nil {
		return err
	}
	defer client.Close()

	// Create sync & comms for concurrent invokations
	ch := make(chan Reservation)
	var wg sync.WaitGroup
	wg.Add(len(locations))

	// Retrieve BQ reservations from every configure region/multi-region
	for _, location := range locations {
		// Create a per-region routine to avoid blocking on I/O during API calls
		go retrieveReservationLocation(ctx, client, project, location, ch, &wg)
	}

	go func() {
		// Synchronize routines and close channel
		wg.Wait()
		close(ch)
	}()

	// Read found reservations into state
	for reservation := range ch {
		id := fmt.Sprintf("%s.%s", reservation.Location, reservation.Name)
		state.Reservations[id] = reservation
	}

	return nil
}