diff --git a/lib/meditate.ex b/lib/meditate.ex index 8412dee..036d745 100644 --- a/lib/meditate.ex +++ b/lib/meditate.ex @@ -16,6 +16,8 @@ defmodule Mix.Tasks.Meditate do |> Tracker.start |> Runner.run + if Tracker.complete?, do: Display.congratulate + receive do {:DOWN, _references, :process, watcher, _reason} -> nil end diff --git a/lib/tracker.ex b/lib/tracker.ex index 96640bd..966ecb8 100644 --- a/lib/tracker.ex +++ b/lib/tracker.ex @@ -19,6 +19,11 @@ defmodule Tracker do end) end + def complete? do + {total, completed} = Agent.get(__MODULE__, &(&1)) + total == Enum.count(completed) + end + def summarize({total, completed}) do %{total: total, current: MapSet.size(completed)} end diff --git a/lib/watcher.ex b/lib/watcher.ex index d5a97ad..f2f7636 100644 --- a/lib/watcher.ex +++ b/lib/watcher.ex @@ -12,6 +12,8 @@ defmodule Watcher do rescue e -> Display.show_compile_error(e) end + + if Tracker.complete?, do: Display.congratulate end end end