Skip to content

Instantly share code, notes, and snippets.

@vincent6767
Created August 26, 2018 08:50
Show Gist options
  • Save vincent6767/e565048dac7a0423c4305513d841b2ed to your computer and use it in GitHub Desktop.
Save vincent6767/e565048dac7a0423c4305513d841b2ed to your computer and use it in GitHub Desktop.
Channel: Distributing tasks to Goroutines example
type StreamProcessor struct {}
func (sp *StreamProcessor) Consume(fn func(r *Record) error) {
for {
records, _ := sp.GetRecords() // error is not handled for simplicity purpose
for _, r := range records {
go handleRecord(fn, r) // distributing task across goroutines. the output channel is not included for simplicity purpose
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment