Skip to content

Commit 0030b28

Browse files
author
José Valim
committed
Clean up Path and Task code
1 parent 9c90955 commit 0030b28

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

lib/elixir/lib/path.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ defmodule Path do
6363
:relative -> join(relative_to, path)
6464
:absolute ->
6565
cond do
66-
:binary.first(path) == ?/ and size(path) == 1 ->
66+
path == "/" ->
6767
path
6868
:binary.last(path) == ?/ ->
6969
binary_part(path, 0, byte_size(path) - 1)

lib/elixir/lib/task.ex

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ defmodule Task do
156156
reply
157157
{:DOWN, ^ref, _, _, :noconnection} ->
158158
mfa = {__MODULE__, :await, [task, timeout]}
159-
exit({{:nodedown, get_node(task.pid)}, mfa})
159+
exit({{:nodedown, node(task.pid)}, mfa})
160160
{:DOWN, ^ref, _, _, reason} ->
161161
exit({reason, {__MODULE__, :await, [task, timeout]}})
162162
after
@@ -198,7 +198,7 @@ defmodule Task do
198198
find = fn(%Task{ref: task_ref}) -> task_ref == ref end
199199
case Enum.find(tasks, find) do
200200
%Task{pid: pid} when reason == :noconnection ->
201-
exit({{:nodedown, get_node(pid)}, {__MODULE__, :find, [tasks, msg]}})
201+
exit({{:nodedown, node(pid)}, {__MODULE__, :find, [tasks, msg]}})
202202
%Task{} ->
203203
exit({reason, {__MODULE__, :find, [tasks, msg]}})
204204
nil ->
@@ -209,7 +209,4 @@ defmodule Task do
209209
def find(_tasks, _msg) do
210210
nil
211211
end
212-
213-
defp get_node({_, n}) when is_atom(n), do: n
214-
defp get_node(pid) when is_pid(pid), do: pid
215212
end

lib/elixir/lib/task/supervised.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule Task.Supervised do
22
@moduledoc false
33

44
def start_link(fun) do
5-
:proc_lib.start_link(__MODULE__, :noreply, [fun])
5+
{:ok, :proc_lib.spawn_link(__MODULE__, :noreply, [fun])}
66
end
77

88
def start_link(caller, fun) do
@@ -45,7 +45,6 @@ defmodule Task.Supervised do
4545
end
4646

4747
def noreply(mfa) do
48-
:proc_lib.init_ack({:ok, self()})
4948
apply(mfa)
5049
end
5150

lib/elixir/test/elixir/task_test.exs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ defmodule TaskTest do
9191
end
9292

9393
test "await/1 exits on :noconnection" do
94-
node = {:unknown, :unknown@node}
95-
assert catch_noconnection(node) == {:nodedown, :unknown@node}
96-
assert catch_noconnection(self) == {:nodedown, self}
94+
ref = make_ref()
95+
task = %Task{ref: ref, pid: self()}
96+
send self(), {:DOWN, ref, self(), self(), :noconnection}
97+
assert catch_exit(Task.await(task)) |> elem(0) == {:nodedown, :nonode@nohost}
9798
end
9899

99100
test "find/2" do
@@ -106,11 +107,4 @@ defmodule TaskTest do
106107
assert catch_exit(Task.find([task], msg)) ==
107108
{:kill, {Task, :find, [[task], msg]}}
108109
end
109-
110-
defp catch_noconnection(process) do
111-
ref = make_ref()
112-
task = %Task{ref: ref, pid: process}
113-
send self(), {:DOWN, ref, process, self(), :noconnection}
114-
catch_exit(Task.await(task)) |> elem(0)
115-
end
116110
end

0 commit comments

Comments
 (0)