Search⌘ K
AI Features

Implementing the QuizManager with Processes

Explore how to build and manage a QuizManager in Elixir using GenServer. Learn to initialize state, handle calls for creating quizzes, and maintain isolated process boundaries in OTP. This lesson helps you understand callbacks, state management, and error handling for reliable application components.

QuizManager

The quiz manager will start with an empty map:

  • We’ll add quizzes to it through a call to :build_quiz.

  • Then, we’ll add templates to a quiz in the store through a call to :add_template.

  • We’ll add a function to let our users look up a quiz by name.

Declaring our boundary

We’ll open up /lib/mastery/boundary/quiz_manager.ex. It’s a straight Elixir module that looks like this:

C++
defmodule Mastery.Boundary.QuizManager do
alias Mastery.Core.Quiz
use GenServer
end
  • We declare the module and setup our initial aliases for Quiz.

  • Then we use GenServer. The use function is an Elixir macro. As we know, macros are code ...