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.

Show HN: Parex – Simple Elixir module for parallel execution

43 pointsby hacker314159about 10 years ago

4 comments

koudelkaabout 10 years ago
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>
shepardrtcabout 10 years ago
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 未加载
whichdanabout 10 years ago
In your parallel code sample, hang2 is only 1000ms instead of 5000ms.<p>This is very cool though!
评论 #9602467 未加载
asa400about 10 years ago
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.