conductor.ex 728 Bytes
Newer Older
Jens-Christian Fischer's avatar
Jens-Christian Fischer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
defmodule Grengine.Conductor do

  use GenServer
  require Logger

  def start_link, do: GenServer.start_link(__MODULE__, 1000, name: __MODULE__)

  def init(state) do
    tick()

    {:ok, state}
  end

  defp tick, do: Process.send_after(self(), :tick, state)

  def handle_info(:tick, state) do
    Logger.info("handle tick")
    get_performances
    |> Enum.each fn perf ->
      do_performance(perf)
    end
    tick()
    {:noreply, state)


  end

  def get_performances do
    # see https://github.com/paulanthonywilson/gproc_select_examples/blob/master/test/gproc_select_test.exs
    matcher = :ets.fun2ms(fn x -> x end)
    :gproc.select(matcher)
  end

  def do_performance(perf) do
    Logger.info(perf)
  end


end