package main
import (
"fmt"
)
func files(fs []string) <-chan string{
c := make(chan string, 1000) //带1000个缓冲的channel,1000个以内不会阻塞
go func(){
for _, f := range fs{
c <- f
}
close(c) //切片内所有文件发送完毕,关闭
}()
return c
}
func filterSize(in <-chan string) <-chan string{
c := make(chan string, 1000) //带1000个缓冲的channel,1000个以内不会阻塞
go func (){
for i := range in{
fmt.Println("filter size got:", i)
if i == "123.txt" || i == "456.txt"{
c <- i
}
}
close(c)
}()
return c
}
func main() {
fmt.Println("file filter service")
fs := []string{"123.txt","456.txt","789.txt","1222.txt"}
c := filterSize(files(fs))
for i := range c{ //阻塞main gorouting, 循环取channel中的数据,直到channel关闭
fmt.Println("main got:", i)
}
}
输出:
file filter service
filter size func got: 123.txt
filter size func got: 456.txt
filter size func got: 789.txt
filter size func got: 1222.txt
main got: 123.txt
main got: 456.txt
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- Go-源码文件的分类和含义
- 如何用二元分类器解决一个多分类任务?
- Tips | 如何用二元分类器解决一个多分类任务?
- sklearn kMeans 分类实战,对沪深300的每日涨跌进行分类
- 多分类实现方式介绍和在 Spark 上实现多分类逻辑回归
- 上海居民快被垃圾分类逼疯!这个深度学习技术帮你做到垃圾自动分类
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Shallows
Nicholas Carr / W. W. Norton & Company / 2011-6-6 / USD 15.95
"Is Google making us stupid?" When Nicholas Carr posed that question, in a celebrated Atlantic Monthly cover story, he tapped into a well of anxiety about how the Internet is changing us. He also crys......一起来看看 《The Shallows》 这本书的介绍吧!