Hello All,
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.
Thanks for your help.
评论:
HappyVictory:
Killing_Spark:its typically used for threading;
threading is most commonly used when you need 2 cpu loops, ex:
go DrawAllUI() go Sort1millionRows() go HandleUserInputWithNoLag()
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
typically MS windows and other UI's use 'message passing' to handle events between threads.... which is like javascript events, or callbacks:
sendMessage(MyApp, WM_EventSomething, DATA1, DATA2) //is roughly equivalent to foo.eventnotify('click', {data: asdf})
and these are cross-thread communication
but now you can use channels too to communicate between thread:
events <- someObjectGenerator('click', map[string]int{"x" : 0, "y" : 0})
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
caseynashvegas:https://github.com/killingspark/restic-cronned
The jobs take advantage of channels to get triggered.
anonfunction:Definitely not perfect code but I'm using channels in a simple chat server here https://github.com/caseylmanus/runtelchat
antoaravinth:
boyter:Wow, thanks. Looks neat and at the same time eligible for the beginners.
Been using them in a pipeline for a replacement for cloc I have been working on https://github.com/boyter/scc
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.
