Skip to content

Instantly share code, notes, and snippets.

@nemith
Last active December 21, 2015 02:49
Show Gist options
  • Select an option

  • Save nemith/6238124 to your computer and use it in GitHub Desktop.

Select an option

Save nemith/6238124 to your computer and use it in GitHub Desktop.
package main
import "os"
//import "log"
import "io"
import "time"
import "fmt"
import "bytes"
import "runtime"
func readIn(ch chan string) {
char := make([]byte, 1)
var buf bytes.Buffer
for {
fmt.Printf("There")
_, err := io.ReadFull(os.Stdin, char)
if err == io.EOF {
} else {
os.Stdout.Write(char)
buf.WriteByte(char[0])
if char[0] == '\n' {
ch <- buf.String()
}
}
}
}
func main() {
runtime.GOMAXPROCS(2)
chIn := make(chan string, 1)
chTick := time.Tick(1e8)
file, err = os.Create("tee.txt")
go readIn(chIn)
select {
case input, open := <-chIn:
if !open {
return
}
file.Write(input)
case <-chTick:
file.Write(" -- TICK --\n")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment