dongmopu6734 2018-11-27 16:59
浏览 24

读取和写入同一通道的工作池

I need your help. Currently i'm trying to create a worker pool that reads continuous jobs from a channel and then produces the result to the same channel it is reading from to then do work and produce the result to the same channel. you get the idea sorta like recursion. Is there any way to make this possible? I would really your appreciate advice on design patterns to implement this solution using go routines as a worker pool and channels to read in jobs and then from the same worker pool write the result of that job to the same channel to keep working. Thank you.

  • 写回答

1条回答 默认 最新

  • dtncv04228 2018-11-27 17:07
    关注

    There is no reason why something can't (from Go's perspective) write back to a channel after reading it:

    func Foo(c chan int) {
      x := <-c
      // do something to x
      c <- x
    }
    

    This is weird though... And honestly would not recommend it. Normally I have seen a system composed of several channels with data being passed down and not entering cycles. Think trees instead of graphs.

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作