تعدد الإرسال باستخدام Select
تسمح select للـ Goroutine بانتظار عدة عمليات اتصال. إنها مثل جملة switch ولكن للقنوات.
go select { case msg1 := <-ch1: fmt.Println("Received", msg1) case ch2 <- "hi": fmt.Println("Sent hi") case <-time.After(time.Second): fmt.Println("Timeout") }
هذا أمر ضروري لتنفيذ فترات الانتظار (timeouts) ومنطق الإلغاء في الخدمات المصغرة.