Exemple #1
0
func main() {
	var est estimation.Estimator
	est = new(estimation.TwomomentsChan)
	var stdin *bufio.Scanner
	stdin = bufio.NewScanner(os.Stdin)
	log.Print("Starting to read\n")
	//setup file reader
	inchan := make(chan float64)
	go utils.CatFloat(stdin, inchan)
	//output print server
	outchan := make(chan string)
	go utils.Print(os.Stdout, outchan)
	//main loop
	var number float64
	var ok bool
	for {
		select {
		case number, ok = <-inchan:
			if ok {
				est.Push(number)
			}
		}

		if !ok {
			//the channel has closed no new data is coming
			break
		}
		outchan <- est.String()
	}
}
Exemple #2
0
//getInput: Take a filename and return a channel of the floats contained in the file.
func getInput(filename string) (chan float64, error) {
	var fp *bufio.Scanner
	file, err := os.Open(filename)
	if err != nil {
		log.Println(file)
	}
	fp = bufio.NewScanner(file)
	log.Printf("Making input channel from file\n")
	inchan := make(chan float64)
	go utils.CatFloat(fp, inchan)
	return inchan, err
}