TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Go package: fanout – make writing parallel code even easier

42 pointsby sunfminover 10 years ago
hide goroutines and channels from developer.

8 comments

TheDongover 10 years ago
Oh, hey, it&#x27;s a generic package that means you lose type safety and saves you from writing roughly 10 lines of code.<p>Buffered channels + goroutines + WaitGroup already allow you to implement this trivially, and because channels are builtin generic, you can do it without the nasty type casts. Really, []interface{} is a terrible type to work with.
评论 #8866629 未加载
评论 #8866342 未加载
评论 #8867168 未加载
jwsover 10 years ago
Just yesterday I was staring at some of my go code thinking that channels are the &quot;goto&quot; of concurrency. You can make just about anything with them, but to understand code you have to read it all, hold it in your head, and reason about all possible outcomes. In the &#x27;60s that&#x27;s how flow of control was done. As the &#x27;70s went by &quot;structured programming&quot; came in and exotic things like <i>while</i> loops, <i>switch</i> statements, and functions that you could only enter at the top (so limiting!) became the norm.<p>This post proposes a level of abstraction to take a common 10 line idiom and abstract it to a word. I&#x27;d much rather read code with the abstraction. (In this case it is clean to read, but there are many complicated patterns in common use involving auxiliary chans for cancellation and timeouts.) Sadly, this is where it collides with the go language designers. Go is anti-abstraction by design. If you don&#x27;t like that then you descend into <i>interface{}</i> hell and manual runtime type checking, or change languages, or just repeat yourself a lot and pray you get the fiddly bits right each time.
评论 #8867017 未加载
评论 #8867138 未加载
goykasiover 10 years ago
I wrote a similar Go package for running work loads in parallel, but I used beanstalkd for job&#x2F;result transport. This allows me a bit more freedom to spread the workers&#x2F;requesters across my network. It&#x27;s a bit rough around the edges and could use some refactoring, but it works well for my uses.<p><a href="https://github.com/eramus/worker" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;eramus&#x2F;worker</a>
评论 #8866383 未加载
zzzcpanover 10 years ago
Seems to be way too trivial for a library: <a href="http://play.golang.org/p/U0URukpeO3" rel="nofollow">http:&#x2F;&#x2F;play.golang.org&#x2F;p&#x2F;U0URukpeO3</a><p>Although I like the idea of having some kind of API to spread the work across multiple machines, since channels are slow anyway.
drtse4over 10 years ago
&gt;How does it make the program run faster?<p>Sunfmin, wrong answer, you&#x27;d have a 20x improvement with 20 workers only with 20 cores (ignoring the limited overhead), regardless of the number of workers your queue of jobs will be consumed in number_of_jobs*single_job_duration&#x2F;GOMAXPROCS.
评论 #8866345 未加载
bradheover 10 years ago
Why does this need to be a dependency that you bring on? This is a trivial pattern.
AYBABTMEover 10 years ago
Write yourself the 20 lines needed before pulling an extra 3rd party deps just for that.<p>The cost of having another 3rd party deps is greater than the seconds you save from using this.
StavrosKover 10 years ago
I&#x27;m not sure what the usefulness of this is (apart from saving you from writing one or two functions yourself), isn&#x27;t it just a parallel queue?
评论 #8866302 未加载
评论 #8866308 未加载