about summary refs log tree commit diff
path: root/assessments/semiprimes/server/lib/sup.ex
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-12-12T01·04+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-12-12T01·04+0000
commit714ec29743bd90257ed7607635abe885df01267d (patch)
treef89609c53248ff43f8d336c0afa33f24aa0e613c /assessments/semiprimes/server/lib/sup.ex
parentc0a88ba7d5524fdaca5d32241676b8bb26e6c3eb (diff)
Define Cache and convert app to OTP
Define a simple in-memory key-value store for our cache.

TL;DR:
- Define `Cache` as a simple state-keeping `Agent`
- Define `Sup`, which starts our Cache process
- Define `App`, which starts our Supervisor process
- Whitelist `App` in `mix.exs`, so that it starts after calling `iex -S mix`
Diffstat (limited to 'assessments/semiprimes/server/lib/sup.ex')
-rw-r--r--assessments/semiprimes/server/lib/sup.ex21
1 files changed, 21 insertions, 0 deletions
diff --git a/assessments/semiprimes/server/lib/sup.ex b/assessments/semiprimes/server/lib/sup.ex
new file mode 100644
index 000000000000..ea02ce30e7b9
--- /dev/null
+++ b/assessments/semiprimes/server/lib/sup.ex
@@ -0,0 +1,21 @@
+defmodule Sup do
+  @moduledoc """
+  Top-level supervisor for our OTP application. For now, this supervisor starts
+  and monitors our cache.
+  """
+
+  use Supervisor
+
+  def start_link(opts \\ []) do
+    Supervisor.start_link(__MODULE__, :ok, opts)
+  end
+
+  @impl true
+  def init(:ok) do
+    children = [
+      Cache
+    ]
+
+    Supervisor.init(children, strategy: :one_for_one)
+  end
+end