Congratulate when koans are complete

This commit is contained in:
Jay Hayes
2016-04-26 17:35:31 -05:00
parent 7903923e36
commit 6ae1cae4b8
3 changed files with 9 additions and 0 deletions

View File

@@ -16,6 +16,8 @@ defmodule Mix.Tasks.Meditate do
|> Tracker.start |> Tracker.start
|> Runner.run |> Runner.run
if Tracker.complete?, do: Display.congratulate
receive do receive do
{:DOWN, _references, :process, watcher, _reason} -> nil {:DOWN, _references, :process, watcher, _reason} -> nil
end end

View File

@@ -19,6 +19,11 @@ defmodule Tracker do
end) end)
end end
def complete? do
{total, completed} = Agent.get(__MODULE__, &(&1))
total == Enum.count(completed)
end
def summarize({total, completed}) do def summarize({total, completed}) do
%{total: total, current: MapSet.size(completed)} %{total: total, current: MapSet.size(completed)}
end end

View File

@@ -12,6 +12,8 @@ defmodule Watcher do
rescue rescue
e -> Display.show_compile_error(e) e -> Display.show_compile_error(e)
end end
if Tracker.complete?, do: Display.congratulate
end end
end end
end end