Show explicit example of named agents

This commit is contained in:
Jay Hayes
2016-05-04 19:57:37 -05:00
parent f5af10d87a
commit 7711936893
2 changed files with 8 additions and 2 deletions

View File

@@ -2,8 +2,13 @@ defmodule Agents do
use Koans
koan "Agents maintain state, so you can ask them about it" do
Agent.start_link(fn() -> "Hi there" end, name: __MODULE__)
assert Agent.get(__MODULE__, &(&1)) == ___
{:ok, pid} = Agent.start_link(fn -> "Hi there" end)
assert Agent.get(pid, &(&1)) == ___
end
koan "Agents may also be named so that you don't have to keep the pid around" do
Agent.start_link(fn -> "Why hello" end, name: AgentSmith)
assert Agent.get(AgentSmith, &(&1)) == ___
end
koan "Update to update the state" do

View File

@@ -5,6 +5,7 @@ defmodule AgentTests do
test "Agents" do
answers = [
"Hi there",
"Why hello",
"HI THERE",
{:multiple, [["Milk"], ["Bread", "Milk"]]},
false,