Permalink
Browse files

Using a separate process

  • Loading branch information...
BjRo committed Jan 19, 2014
1 parent 34722bf commit 1edd49ec0f56bf9d4499edea94a456fff6cdbd9c
Showing with 21 additions and 2 deletions.
  1. +1 −1 lib/ap.ex
  2. +19 −0 lib/ap/printer.ex
  3. +1 −1 lib/ap/supervisor.ex
View
@@ -6,6 +6,6 @@ defmodule AP do
end
def ap(data, options // []) do
- IO.puts AP.Format.format(data, options)
+ AP.Printer.print(data, options)
end
end
View
@@ -0,0 +1,19 @@
+defmodule AP.Printer do
+ use GenServer.Behaviour
+ import AP.Format
+
+ def start_link(args // [], opts // []) do
+ :gen_server.start_link({:local, __MODULE__}, __MODULE__, args, opts)
+ end
+
+ def print(data, opts) do
+ :gen_server.cast(__MODULE__, {:print, data, opts})
+ end
+
+ def init(_), do: { :ok, [] }
+
+ def handle_cast({:print, data, opts}, state) do
+ format(data, opts) |> IO.puts
+ { :noreply, state }
+ end
+end
View
@@ -7,7 +7,7 @@ defmodule AP.Supervisor do
def init([]) do
children = [
- # worker(Ap.Worker, [])
+ worker(AP.Printer, [])
]
supervise(children, strategy: :one_for_one)

0 comments on commit 1edd49e

Please sign in to comment.