dongxingqiu7943 2017-06-21 07:32
浏览 83
已采纳

通过不同Go包/文件上的一个通道发送和接收数据

+----------------+                       +-----------------+
| Channel foo    |                       | Channel foo     |
| a.go           |                       | b.go            |
+----------------+                       +-----------------+
       |                                          |
       |__________________________________________|
        Send or receive data through 'foo' channel

Can I create two Go source code files and send or receive data through one channel such as described from image/illustration above? So, these files could communicate each other with sending data while source code is running.

  • 写回答

1条回答 默认 最新

  • duanlinpi0265 2017-06-21 09:05
    关注

    Channels are just variables in Go, like int, []byte or bool. If you can pass any variables between packages, you can obviously then pass channels between packages as well. And once you've passed a channel from one package to another, you are of course free to use it there, just as you would any other variable. That means you can send data in one package, and receive it in another.

    Ultimately channels wouldn't be very useful if they couldn't be shared between packages.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动