商君

导航

2018年10月19日 #

Go Example--工作池

摘要: ```go package main import ( "fmt" "time" ) func main() { jobs :=make(chan int,100) results := make(chan int,100) //启动3个协程 for w:=1;w 阅读全文

posted @ 2018-10-19 17:15 漫步者01 阅读(85) 评论(0) 推荐(0) 编辑

Go Example--打点器

摘要: ```go package main import ( "time" "fmt" ) func main() { // 定时器 是当你想要在未来某一刻执行一次时使用的 - 打点器 // 则是当你想要在固定的时间间隔重复执行准备的。这里是一个打点器的例子, // 它将定时的执行,直到我们将它停止。 ticker := time.NewTicker(time.Millisecond*5... 阅读全文

posted @ 2018-10-19 16:52 漫步者01 阅读(150) 评论(0) 推荐(0) 编辑

Go Example--定时器

摘要: ```go package main import ( "fmt" "time" ) func main() { //定时器2s timer1 := time.NewTimer(time.Second 2) //读取通道,阻塞2s 阅读全文

posted @ 2018-10-19 16:40 漫步者01 阅读(105) 评论(0) 推荐(0) 编辑

Go Example--通道遍历

摘要: ```go package main import ( "fmt" ) func main() { queue := make(chan string, 2) queue 阅读全文

posted @ 2018-10-19 16:27 漫步者01 阅读(125) 评论(0) 推荐(0) 编辑

Go Example--关闭通道

摘要: ```go package main import ( "fmt" ) func main() { jobs := make(chan int, 5) done := make(chan bool) go func() { for { //读取通道方式, val,ok := 阅读全文

posted @ 2018-10-19 16:19 漫步者01 阅读(169) 评论(0) 推荐(0) 编辑

Go Example--通道非阻塞

摘要: ```go package main import ( "fmt" ) func main() { messages := make(chan string) signals := make(chan bool) //常规的通过通道发送和接收数据是阻塞的。然而,我们可以使用带一个 default子句 阅读全文

posted @ 2018-10-19 15:45 漫步者01 阅读(121) 评论(0) 推荐(0) 编辑

Go Example--超时处理

摘要: ```go package main import ( "fmt" "time" ) func main() { c1 := make(chan string, 1) go func() { time.Sleep(time.Second 2) c1 阅读全文

posted @ 2018-10-19 15:22 漫步者01 阅读(106) 评论(0) 推荐(0) 编辑

Go Example--通道选择器

摘要: ```go package main import ( "fmt" "time" ) func main() { c1 := make(chan string) c2 := make(chan string) go func() { time.Sleep(time.Second 1) c1 阅读全文

posted @ 2018-10-19 15:13 漫步者01 阅读(93) 评论(0) 推荐(0) 编辑

Go Example--通道方向

摘要: ```go package main import "fmt" func main() { pings := make(chan string, 1) pongs := make(chan string, 1) ping(pings, "passwd message") pong(pings, po 阅读全文

posted @ 2018-10-19 15:07 漫步者01 阅读(130) 评论(0) 推荐(0) 编辑