package main

import (
	"context"
	"fmt"
	"log"
	"time"
	"training/api"
)

func main() {
	isbns := []string{
		"1788626540",
		"178712598X",
		"1838643575",
		"0672338033",
		"1788475275",
		"1788622596",
		"1788294289",
		"1788627911",
		"1838554491",
	}

	ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
	defer cancel()

	results := api.Books(ctx, isbns)
	for i := 0; i < len(isbns); i++ {
		select {
		case result := <-results:
			if result.Err != nil {
				log.Fatal(result.Err)
			}
			fmt.Println(result.Book.Title)
		case <-ctx.Done():
			log.Fatal(ctx.Err())
		}
	}
}
