Created
August 26, 2018 08:50
-
-
Save vincent6767/e565048dac7a0423c4305513d841b2ed to your computer and use it in GitHub Desktop.
Channel: Distributing tasks to Goroutines example
This file contains 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
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