package main

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

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

	timer := time.NewTimer(time.Second * 30)
	defer timer.Stop()

	results := api.Books(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 <-timer.C:
			log.Fatal("timeout exceeded")
		}
	}
}
