I'm rather new in Golang, but working hard on understanding this great language! Please, help me in this..
I have 2 chanels. "In" and "Out" chanels
in, out := make(chan Work), make(chan Work)
I set up goroutines workers that are listening for in chanel, grab work and do it. I have some work, that i would send into In chanel.
When Work is done by worker, it writes to the Out chanel.
func worker(in <-chan Work, out chan<- Work, wg *sync.WaitGroup) {
for w := range in {
// do some work with the Work
time.Sleep(time.Duration(w.Z))
out <- w
}
wg.Done()
}
When all work is done I close both chanels at the write time of the program.
Now I want to write the results of done work in OUT chanel, but to separate all in some parts, for example, if work type would be like this :
type Work struct {
Date string
WorkType string
Filters []Filter
}
if WorkType is "firstType" I would like to send the done work to one chanel, and if WorkType is "secondType" to second chan... But there might be over 20 types of work .. How to resolve this case in a better way?
Can I set up chanels in chanel OUT, and grab data from this sub chanels?
p.s.: Forgive me my noob questions, please..