Last active
November 11, 2019 02:03
-
-
Save ohta-rh/254b84ddf666947e92405abeeefc2dc1 to your computer and use it in GitHub Desktop.
Elixirでコアをつかいきってみる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Multicore do | |
@moduledoc """ | |
Documentation for Multicore. | |
""" | |
@doc """ | |
Hello world. | |
## Examples | |
iex> Multicore.hello() | |
:world | |
""" | |
def sum(from, to) do | |
Enum.reduce(from..to, fn x, acc -> x+acc end) |> IO.puts | |
end | |
def main do | |
0..1000 | |
|> Enum.map(fn _ -> Task.async(fn -> sum(1, 100000) end) end) | |
|> Enum.map(fn x -> Task.await(x) end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment