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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Show HN: Parex – Simple Elixir module for parallel execution

43 点作者 hacker314159大约 10 年前

4 条评论

koudelka大约 10 年前
The Task module is great for this kind of thing, too. <a href="http:&#x2F;&#x2F;elixir-lang.org&#x2F;docs&#x2F;v1.0&#x2F;elixir&#x2F;Task.html" rel="nofollow">http:&#x2F;&#x2F;elixir-lang.org&#x2F;docs&#x2F;v1.0&#x2F;elixir&#x2F;Task.html</a><p><pre><code> [ add: fn() -&gt; 1+2 end, hang1: fn() -&gt; :timer.sleep(1000) end, hang2: fn() -&gt; :timer.sleep(5000) end ] |&gt; Enum.map(fn {k, t} -&gt; {k, Task.async(t)} end) |&gt; Enum.map(fn {k, t} -&gt; {k, Task.await(t, :infinity)} end)</code></pre>
shepardrtc大约 10 年前
So this is having a single (Erlang VM) process run code on as many cores as it can? Is this designed for a sequential program so that you don&#x27;t have to split it up into processes? I&#x27;m still learning Erlang&#x2F;Elixir, so I apologize if this is a stupid question.
评论 #9602735 未加载
评论 #9602767 未加载
评论 #9602710 未加载
whichdan大约 10 年前
In your parallel code sample, hang2 is only 1000ms instead of 5000ms.<p>This is very cool though!
评论 #9602467 未加载
asa400大约 10 年前
Very cool. I love seeing stuff like this: simple things that illustrate how easy it is to get going with concurrent programming in Elixir&#x2F;Erlang.