golang select为case添加优先级
func worker(highPriority, lowPriority <-chan int, stopCh chan struct{}) { for { select { case <-stopCh: return case job := <-highPriority: // 优先处理高优先级通道 fmt.Println("High priority job:", job) default: select { case job := <-highPriority: // 再次检查高优先级 fmt.Println("High priority job:", job) case job := <-lowPriority: // 处理低优先级 fmt.Println("Low priority job:", job) case <-stopCh: return } } } }
浙公网安备 33010602011771号