Created
November 28, 2016 21:06
-
-
Save eriknelson/1b16b57b0f00c286aa66127104c05ef4 to your computer and use it in GitHub Desktop.
Scanner demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "bufio" | |
| "fmt" | |
| "os/exec" | |
| ) | |
| const xfile = "/home/nelsk/dev/go/src/ticker/ticker" | |
| func main() { | |
| cmd := exec.Command(xfile) | |
| cmd2 := exec.Command(xfile) | |
| readCloser, _ := cmd.StdoutPipe() | |
| scanner := bufio.NewScanner(readCloser) | |
| readCloser2, _ := cmd2.StdoutPipe() | |
| scanner2 := bufio.NewScanner(readCloser2) | |
| cmd.Start() | |
| cmd2.Start() | |
| go func() { | |
| for scanner.Scan() { | |
| fmt.Println(scanner.Text()) | |
| } | |
| }() | |
| fmt.Println("Waiting") | |
| go func() { | |
| for scanner2.Scan() { | |
| fmt.Println(scanner2.Text()) | |
| } | |
| }() | |
| cmd.Wait() | |
| cmd2.Wait() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "time" | |
| ) | |
| func main() { | |
| counter := 0 | |
| for { | |
| counter++ | |
| fmt.Printf("Ticker %d\n", counter) | |
| if counter == 5 { | |
| break | |
| } | |
| time.Sleep(time.Duration(500) * time.Millisecond) | |
| } | |
| fmt.Println("done.") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment