add .formatter.exs + format

This commit is contained in:
Martino Visintin
2018-05-22 21:46:54 +01:00
parent 08c90ce0d8
commit b07df7c780
52 changed files with 332 additions and 264 deletions

View File

@@ -10,23 +10,26 @@ defmodule Tasks do
end
koan "If you don't need a result, use start_link/1" do
{result, _pid} = Task.start_link(fn -> 1+1 end)
{result, _pid} = Task.start_link(fn -> 1 + 1 end)
assert result == ___
end
koan "Yield returns nil if the task isn't done yet" do
handle = Task.async(fn ->
:timer.sleep(100)
3 * 3
end)
handle =
Task.async(fn ->
:timer.sleep(100)
3 * 3
end)
assert Task.yield(handle, 10) == ___
end
koan "Tasks can be aborted with shutdown" do
handle = Task.async(fn ->
:timer.sleep(100)
3 * 3
end)
handle =
Task.async(fn ->
:timer.sleep(100)
3 * 3
end)
%Task{pid: pid} = handle
Task.shutdown(handle)
@@ -41,10 +44,11 @@ defmodule Tasks do
end
koan "You can yield to multiple tasks at once and extract the results" do
squares = [1, 2, 3, 4]
|> Enum.map(fn(number) -> Task.async(fn -> number * number end) end)
|> Task.yield_many(100)
|> Enum.map(fn({_task,{:ok, result}}) -> result end)
squares =
[1, 2, 3, 4]
|> Enum.map(fn number -> Task.async(fn -> number * number end) end)
|> Task.yield_many(100)
|> Enum.map(fn {_task, {:ok, result}} -> result end)
assert squares == ___
end