package main
import (
"fmt"
"math/rand"
"time"
)
func production(channel chan<- string) {
for {
channel <- fmt.Sprintf("%v", rand.Float64())
time.Sleep(time.Second * time.Duration(1))
}
}
func customer(channel <-chan string) {
for {
message := <-channel
fmt.Println(message)
}
}
func main() {
channel := make(chan string, 10)
go production(channel)
customer(channel)
}
时间: 2024-10-26 20:25:10