此代码将永远不会退出,直到它为len(queues)
次做处理。它不是一个并发代码 - 全部在主体中 - 并且没有告诉代码停止的信号。问题就在这里:
case "run":
// Installing the service
installed, err := service.Install()
logError(err, installed)
// Starting the service
started, err := service.Start()
logError(err, started)
if err == nil {
// Creating a goroutine and executing the queue's processes in parallel
for i := 0; i < len(queues); i++ {
go startProcessing(queues[i])
time.Sleep(time.Second) // Waiting for other functions to execute
}
select {} // To prevent the goroutine from exiting the main func
}
fmt.Println(started)
因为它可以看出,select{}
行会坐在那里跑,直到永远! :)最好是有移动这种情况下的条款,到他们自己够程,并有一个退出信号是这样的:
select {
case <-quit:
return
}
虽然这不是处理开始在Go应用程序/停止最彻底的方法;它只是表明了问题。