Go 消费者和生产者的简单例子
2016-02-26 08:49
465 查看
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)
}本文出自 “东神要一打五” 博客,谢绝转载!
相关文章推荐
- Go 消费者和生产者的简单例子
- Go 消费者和生产者的简单例子
- ubuntu下google 拼音输入法的安装
- Django框架学习
- VIEWGOOD(远古)P2P流媒体直播系统的设计与实现
- go语言指针访问结构体的方法
- UVA 225(p214)----Golygons
- NSDate和NSDateFormatter的使⽤、Category、Extension、Protocol、delegate
- Learn Some Framework-3 From Zygote to HOME
- LightOJ 1259 Goldbach`s Conjecture(数论)
- Google Guava官方教程(中文版 转载)
- NS2中GOD的使用
- Django学习随手记(四)
- Django~automated tests
- 仅当使用了列的列表,并且IDENTITY_INSERT为ON时,才能在表'goldlog'中为标识列指定显式值
- Pymongo: TypeError: if no direction is specified, key_or_list must be an instance of list
- Django~Models1
- mongoose使用的抓狂
- golang笔记——流程控制
- GoogLeNet系列解读