Created
December 31, 2014 00:35
-
-
Save atedja/92fb0cec3397d9765596 to your computer and use it in GitHub Desktop.
Fan-out example in Go
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" | |
import "bufio" | |
import "os" | |
import "strings" | |
var id int = 0 | |
func WorkerProcess(in <-chan string) { | |
id = id + 1 | |
thisId := id | |
for { | |
fmt.Printf("%d: waiting for input...\n", thisId) | |
input := <-in | |
fmt.Printf("%d: input is: %s\n", thisId, input) | |
} | |
} | |
func main() { | |
input := make(chan string) | |
go WorkerProcess(input) | |
go WorkerProcess(input) | |
go WorkerProcess(input) | |
reader := bufio.NewReader(os.Stdin) | |
for { | |
i, _ := reader.ReadString('\n') | |
i = strings.TrimRight(i, "\n") | |
input <- i | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment