Running with Multiple Users
Explore how to manage multiple user sessions simultaneously in Elixir using OTP. Learn to track user emails and quizzes, control process lifecycles, and inspect internal states, ensuring robust quiz session management and proper process shutdown after completion.
This trial run will be different from all of the others. We’re going to assume our user interface will keep track of two things:
-
The email address for each user.
-
The quiz they are taking at any given time.
Other than that, we’ll make no assumptions at all. We’ll refer to all processes by some name, and we’ll keep track of more than one user at a time.
Tracking data
Let’s open up the iex terminal and get started:
Executable
Output
iex(1)> alias Mastery.Examples.Math
Mastery.Examples.Math
iex(2)> email1 = "mathter_of_the_universe@example.com"
"mathter_of_the_universe@example.com"
iex(3)> email2 = "mam_math@example.com" ...