Score
0
Watch 25 Star 104 Fork 12

Gitee星球的小活动 / 第 0 届 代码编故事接力赛

Join us
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
让我们点燃程序员写作之魂,一人用代码写一段故事玩玩吧~ spread retract

Clone or download
golang-bit_rain.go 732 Bytes
Copy Edit Web IDE Raw Blame History
djokeme authored 2020-03-24 15:37 . golang下一场二进制雨
// golang下一场二进制雨
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
fmt.Println("god: let it rain") // 神说:要下一场雨才好
fmt.Println("coder: bit rain") // 程序员:那就来一场二进制雨
SetupCloseHandler()
time.Sleep(2 * time.Second)
c := make(chan int)
// 消费
go func() {
for {
fmt.Print(<-c, " ")
}
}()
// 生产
for {
select {
case c <- 0:
case c <- 1:
}
}
}
func SetupCloseHandler() {
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
fmt.Println("\n rain stopped")
os.Exit(0)
}()
}

Comment ( 0 )

Sign in for post a comment

1
https://gitee.com/Selected-Activities/Code-relay.git
git@gitee.com:Selected-Activities/Code-relay.git
Selected-Activities
Code-relay
第 0 届 代码编故事接力赛
master

Help Search

220309 7019f5b6 1899542 220318 4015cbb9 1899542