Rearrange existing koans to paint a clearer picture
This commit is contained in:
@@ -21,6 +21,21 @@ defmodule Processes do
|
|||||||
assert Process.alive?(pid) == ___
|
assert Process.alive?(pid) == ___
|
||||||
end
|
end
|
||||||
|
|
||||||
|
koan "You can kill processes other than yourself" do
|
||||||
|
pid = spawn(fn -> receive do end end)
|
||||||
|
|
||||||
|
assert Process.alive?(pid) == ___
|
||||||
|
Process.exit(pid, :kill)
|
||||||
|
assert Process.alive?(pid) == ___
|
||||||
|
end
|
||||||
|
|
||||||
|
koan "However, trying to exit normally has no effect" do
|
||||||
|
pid = spawn(fn -> receive do end end)
|
||||||
|
Process.exit(pid, :normal)
|
||||||
|
|
||||||
|
assert Process.alive?(pid) == ___
|
||||||
|
end
|
||||||
|
|
||||||
koan "Processes can send and receive messages; it's like a mailbox!" do
|
koan "Processes can send and receive messages; it's like a mailbox!" do
|
||||||
send self, "hola!"
|
send self, "hola!"
|
||||||
|
|
||||||
@@ -53,14 +68,6 @@ defmodule Processes do
|
|||||||
assert_receive ___
|
assert_receive ___
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "You can also terminate processes other than yourself" do
|
|
||||||
pid = spawn(fn -> receive do end end)
|
|
||||||
|
|
||||||
assert Process.alive?(pid) == ___
|
|
||||||
Process.exit(pid, :kill)
|
|
||||||
assert Process.alive?(pid) == ___
|
|
||||||
end
|
|
||||||
|
|
||||||
koan "Trapping will allow you to react to someone terminating the process" do
|
koan "Trapping will allow you to react to someone terminating the process" do
|
||||||
parent = self
|
parent = self
|
||||||
pid = spawn(fn ->
|
pid = spawn(fn ->
|
||||||
@@ -80,13 +87,6 @@ defmodule Processes do
|
|||||||
assert_receive ___
|
assert_receive ___
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Trying to quit normally has no effect" do
|
|
||||||
pid = spawn(fn -> receive do end end)
|
|
||||||
Process.exit(pid, :normal)
|
|
||||||
|
|
||||||
assert Process.alive?(pid) == ___
|
|
||||||
end
|
|
||||||
|
|
||||||
koan "Parent processes can trap exits for children they are linked to" do
|
koan "Parent processes can trap exits for children they are linked to" do
|
||||||
Process.flag(:trap_exit, true)
|
Process.flag(:trap_exit, true)
|
||||||
spawn_link(fn -> Process.exit(self, :normal) end)
|
spawn_link(fn -> Process.exit(self, :normal) end)
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ defmodule ProcessesTests do
|
|||||||
:running,
|
:running,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
{:multiple, [true, false]},
|
||||||
|
true,
|
||||||
"hola!",
|
"hola!",
|
||||||
:how_are_you?,
|
:how_are_you?,
|
||||||
{:waited_too_long, "I am impatient"},
|
{:waited_too_long, "I am impatient"},
|
||||||
{:multiple, [true, false]},
|
|
||||||
{:exited, :random_reason},
|
{:exited, :random_reason},
|
||||||
true,
|
|
||||||
:normal,
|
:normal,
|
||||||
:normal,
|
:normal,
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user