Open hariprasadraja opened 3 years ago
The for loop is creating n number of go routines, each go routine is reading from the channel. If there is no task to be executed present on the channel i.e channel is empty, then the go routine will terminate.
The for loop is creating n number of go routines, each go routine is reading from the channel. If there is no task to be executed present on the channel i.e channel is empty, then the go routine will terminate.
Well, It won't. try a small program with empty channel in range and observe it.
The for loop is creating n number of go routines, each go routine is reading from the channel. If there is no task to be executed present on the channel i.e channel is empty, then the go routine will terminate.
This is happening because I am closing the JobList channel after adding all the tasks. So the channel accessed by the goroutines is a closed channel.
`
case FIFO:
sort.Sort(ByArrivalTime(jobs))
for _, job := range jobs {
JobList <- job
}
close(JobList)
case LIFO:
sort.Sort(ByArrivalTime(jobs))
for i := len(jobs) - 1; i >= 0; i-- {
JobList <- jobs[i]
}
close(JobList)
case PriorityQueue:
sort.Sort(ByPriority(jobs))
for _, job := range jobs {
JobList <- job
}
close(JobList)
`
Agree. In the case of dynamic jobs, how can you sort the inputs. do you know the input jobs you have received are complete ?
What if It is not going to complete and you are going to get the inputs always like a web server.
https://github.com/sanketmahore/JobSchedulingPOC/blob/de635437ff81946f47028309ab5ad8990435da2a/JobScheduling/jobs.go#L61-L67