Exemple #1
0
// saveHistory periodically saves the line history to the history file
func saveHistory(line *liner.State, stop chan bool) {
	ticker := time.NewTicker(1 * time.Minute)
	defer ticker.Stop()
	for {
		select {
		case <-stop:
			break
		case <-ticker.C:
			if f, err := os.Create(*hist); err != nil {
				if *verbose {
					log.Print("Error writing history file: ", err)
				}
			} else {
				line.WriteHistory(f)
				f.Close()
			}
		}
	}
}