-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
55 lines (48 loc) · 993 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* @Author: your name
* @Date: 2022-04-19 17:48:25
* @LastEditTime: 2022-04-19 18:00:50
* @LastEditors: Please set LastEditors
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @FilePath: /golang-base/sync_pipeline_demo/main.go
*/
package main
import "fmt"
func main() {
buys := buy(10)
builds := build(buys)
packs := pack(builds)
for p := range packs {
fmt.Println(p)
}
}
func buy(n int) <-chan string {
out := make(chan string)
go func() {
defer close(out)
for i := 0; i < n; i++ {
out <- fmt.Sprint("配件", i)
}
}()
return out
}
func build(in <-chan string) <-chan string {
out := make(chan string)
go func() {
defer close(out)
for v := range in {
out <- "组装" + v
}
}()
return out
}
func pack(in <-chan string) <-chan string {
out := make(chan string)
go func() {
defer close(out)
for v := range in {
out <- "打包" + v
}
}()
return out
}