Created
April 28, 2016 11:43
-
-
Save brweber2/56e9a991b023f8b46518e6389b79ce44 to your computer and use it in GitHub Desktop.
This file contains 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 Cats do | |
@base_dir "cats" | |
def run() do | |
pid = start() | |
send pid, {self, "Virginia", "Felix"} | |
receive do | |
resp -> IO.puts "Virginia/Felix: #{inspect resp}" | |
after 5000 -> | |
IO.puts "Timed out waiting for Virginia/Felix" | |
end | |
send pid, {self, "Michigan", "Thomas"} | |
receive do | |
resp -> IO.puts "Michigan/Thomas: #{inspect resp}" | |
after 5000 -> | |
IO.puts "Timed out waiting for Michigan/Thomas" | |
end | |
end | |
def start() do | |
spawn &cat_message/0 | |
end | |
def cat_message() do | |
receive do | |
{from, state, cat} -> | |
send from, find_cat(state, cat) | |
cat_message | |
:quit -> :ok | |
end | |
end | |
def find_cat(state, cat) do | |
[@base_dir, String.downcase(state), String.downcase(cat) <> ".cat"] | |
|> Path.join() | |
|> File.read!() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment