package main

import (
	"fmt"
	"time"
)

func main() {
	ch := make(chan string)

	// 模拟一个耗时 2 秒的慢任务
	go func() {
		time.Sleep(2 * time.Second)
		ch <- "job done"
	}()

	// 用 select 实现 1 秒超时
	select {
	case res := <-ch:
		fmt.Println("received:", res)
	case <-time.After(1 * time.Second):
		fmt.Println("timeout: 1s 内没有收到结果")
	}
}
