在編寫應作為 goroutine 的一部分運行的邏輯時,方法本身應該創建 goroutine 還是應該由調用函數負責?例如,以下哪項更可???在方法中創建 go 例程func longrunning() chan Result { c := make(chan Result) go func() { // Business Logic Here c <- Result{} }() return c}func main() { c := longrunning() // Do additional tasks <-c}留給呼叫者func longrunning() Result { // Business Logic Here return Result{}}func main() { c := make(chan Result) go func() { c <- longrunning() }() // Do additional tasks <-c}
添加回答
舉報
0/150
提交
取消