TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Go package: fanout – make writing parallel code even easier

42 点作者 sunfmin超过 10 年前
hide goroutines and channels from developer.

8 条评论

TheDong超过 10 年前
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 未加载
jws超过 10 年前
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 未加载
goykasi超过 10 年前
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 未加载
zzzcpan超过 10 年前
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.
drtse4超过 10 年前
&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 未加载
bradhe超过 10 年前
Why does this need to be a dependency that you bring on? This is a trivial pattern.
AYBABTME超过 10 年前
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.
StavrosK超过 10 年前
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 未加载