V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
darasion
V2EX  ›  Go 编程语言

关于 channel 与 func, 什么时候应该通过参数传入 chan,什么时候应该返回 chan?

  •  
  •   darasion · 2016-04-19 09:44:31 +08:00 · 1258 次点击
    这是一个创建于 2900 天前的主题,其中的信息可能已经有所发展或是发生改变。
    看了一些文章,比如:
    https://blog.golang.org/pipelines
    https://golang.org/doc/codewalk/sharemem/

    都没细说过这事,大家的经验是?
    2 条回复    2016-04-20 09:58:37 +08:00
    gamexg
        1
    gamexg  
       2016-04-19 10:00:02 +08:00
    多线程时将任务推到 chan ,线程池读取并处理。
    其他语言使用回调函数时, go 返回 chan 实现类似的功能。
    spongebobsun
        2
    spongebobsun  
       2016-04-20 09:58:37 +08:00   ❤️ 1
    干活的 channel 传入 chan 给他,活儿干完了把数据塞回 chan 里面
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3614 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 00:50 · PVG 08:50 · LAX 17:50 · JFK 20:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.