问题现象
当for 和 select结合使用时,break语言是无法跳出for之外的:
package main
import (
"fmt"
"time"
"context"
)
func main(){
d := time.Now().Add(3000 * time.Millisecond)
ctx, cancel := context.WithDeadline(context.Background(), d)
// Even though ctx will be expired, it is good practice to call its
// cancelation function in any case. Failure to do so may keep the
// context and its parent alive longer than necessary.
defer cancel()
for{
select {
case