Beispiel #1
0
func asyncTest(client c.Client, total int) {

	resChan := make(chan *cheshire.Response, 20)
	errorChan := make(chan error, 200)

	start := time.Now().Unix()

	sent := total
	go func() {

		for i := 0; i < total; i++ {
			if i%1000 == 0 {
				log.Printf("Sending %d", i)
			}
			err := client.ApiCall(cheshire.NewRequest("/ping", "GET"), resChan, errorChan)
			if err != nil {
				log.Printf("apicall error %s", err)
				sent--
			}
			// if i % 2 == 0 {
			//     time.Sleep(1 * time.Millisecond)
			// }
		}
	}()
	count := 0

	log.Println("Starting select!")
	for {
		select {
		case res := <-resChan:
			count++
			if count%1000 == 0 {
				log.Printf("Recieved 1000 more, total %d, total time: %d", count, (time.Now().Unix() - start))
				log.Printf("RESULT %s", res)
			}

		case err := <-errorChan:
			count++
			log.Printf("ERROR FROM CHAN %s", err)
		}

		if count == sent {
			log.Println("FINISHED!")
			break
		}
	}

	log.Printf("Pinged %d in %d", total, (time.Now().Unix() - start))

}