İleri
Ders 18 / 22
Select ve Concurrency
select, birden fazla channel işlemini dinler.
go
select {
case m := <-c1:
fmt.Println("c1:", m)
case m := <-c2:
fmt.Println("c2:", m)
case <-time.After(300 * time.Millisecond):
fmt.Println("zaman aşımı")
}Worker pool iskeleti
go
jobs := make(chan int, 10)
results := make(chan int, 10)
for w := 1; w <= 3; w++ {
go func(id int) {
for j := range jobs {
results <- j * 2
}
}(w)
}Alıştırma
İki channel'ı select ile dinle; default ile non-blocking oku.