Search⌘ K
AI Features

Laying Grounds for the Proctor Boundary Server

Explore how to build GenServer reply tuples with optional timeouts to manage quiz scheduling and worker lifecycle in Elixir. Understand handling handle_call and handle_info responses, starting quizzes based on scheduled timeouts, and stopping quizzes at the correct time using OTP features.

Building the reply

Let’s talk about the reply:

  • It needs to set the state of the GenServer and set a timeout, so we’ll get control back for starting the next quiz.

  • In this code, we’re going to make use of a little-used GenServer feature, appending an optional timeout to a :reply tuple.

  • When we’re done, our :reply tuple should look like {:reply, :ok, quizzes, timeout}.

The timeout is optional, so we’ll leave it off if the quizzes are empty.

Our code, then, returns any quizzes that have not yet been started and tacks on a timeout so that we’ll get control back in time to start the next quiz.

With the broad strokes coded, let’s see how we go about building that reply tuple. We’ll fill this in ...