package main import ( "fmt" "time" ) func worker(id int, ch chan int) { for { value := <-ch fmt.Printf("Worker %d received %d\n", id, value) time.Sleep(time.Second) // Simulate some work } } func main() { ch := make(chan int) // Start three worker goroutines for i := 1; i <= 3; i++ { go worker(i, ch) } // Send values to the channel for i := 1; i <= 5; i++ { ch <- i } time.Sleep(3 * time.Second) // Let the workers finish their work close(ch) // Close the channel when done }