<p>Hello All, </p>
<p>I'm reading Golang and want to check if there are any open source project which uses channels in their code base. I would prefer any such libraries/code which will allow the beginner to pick and understand how channels work in real world. </p>
<p>Thanks for your help.</p>
<hr/>**评论:**<br/><br/>HappyVictory: <pre><p>its typically used for threading; </p>
<p>threading is most commonly used when you need 2 cpu loops, ex: </p>
<pre><code>go DrawAllUI()
go Sort1millionRows()
go HandleUserInputWithNoLag()
</code></pre>
<p>for example if you sort 1 million rows of a array while your UI is drawing anything: the mouse would stop responding and the UI would stop drawing</p>
<p>typically MS windows and other UI's use 'message passing' to handle events between threads.... which is like javascript events, or callbacks:</p>
<pre><code>sendMessage(MyApp, WM_EventSomething, DATA1, DATA2)
//is roughly equivalent to
foo.eventnotify('click', {data: asdf})
</code></pre>
<p>and these are cross-thread communication</p>
<p>but now you can use channels too to communicate between thread:</p>
<pre><code>events <- someObjectGenerator('click', map[string]int{"x" : 0, "y" : 0})
</code></pre>
<p>the other main use is to share data between threads ; because while two threads read the same memory block; if both write the same memory at the same time it will corrupt the data</p></pre>Killing_Spark: <pre><p><a href="https://github.com/killingspark/restic-cronned" rel="nofollow">https://github.com/killingspark/restic-cronned</a> </p>
<p>The jobs take advantage of channels to get triggered. </p></pre>caseynashvegas: <pre><p>Definitely not perfect code but I'm using channels in a simple chat server here <a href="https://github.com/caseylmanus/runtelchat" rel="nofollow">https://github.com/caseylmanus/runtelchat</a></p></pre>anonfunction: <pre><p><a href="https://github.com/klauspost/pgzip/search?q=chan" rel="nofollow">https://github.com/klauspost/pgzip/search?q=chan</a></p></pre>antoaravinth: <pre><p>Wow, thanks. Looks neat and at the same time eligible for the beginners.</p></pre>boyter: <pre><p>Been using them in a pipeline for a replacement for cloc I have been working on <a href="https://github.com/boyter/scc" rel="nofollow">https://github.com/boyter/scc</a></p>
<p>I’m a totally new Go developer so nothing fancy is going on in there. I suspect if you are new to it it’s likely to help with understanding. </p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传