Skip to content

Instantly share code, notes, and snippets.

@atedja
Created December 31, 2014 00:35
Show Gist options
  • Save atedja/92fb0cec3397d9765596 to your computer and use it in GitHub Desktop.
Save atedja/92fb0cec3397d9765596 to your computer and use it in GitHub Desktop.
Fan-out example in Go
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