A function has loop which call a go routine inside it with a channel passed into it. After this, I try receiving from channel till it has values.
The go function passes value in channel upon each call.
My channel runs infinitely.
func (m *StreamsDAO) FindOutput(input model.Input) ([]model.Output, error) {
// SOME CODE
var chanNumber int = (input.EndTime - input.StartTime)/60
outputChan := make(chan model.Output, chanNumber)
for i := input.StartTime; i < input.EndTime ;i = i+(slider*60) {
// SOME CODE
go ForEachSlide(i, outputChan)
for outputC := range outputChan {
outputs = append(outputs, outputC)
}
}
return outputs, err
}
func ForEachSlide(i int, outputChan chan model.Output) {
// SOME CODE
outputChan <- output
// close(outputChan)
}
Its looping infinite as there in no stop for receiving from channel. If close channel is used, only single element is received from channel thats as expected, but I need all values from the channel.