Skip to content

Latest commit

 

History

History
84 lines (60 loc) · 2.45 KB

dominoes.livemd

File metadata and controls

84 lines (60 loc) · 2.45 KB

Dominoes

Mix.install([
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"},
  {:tested_cell, github: "brooklinjazz/tested_cell"},
  {:utils, path: "#{__DIR__}/../utils"}
])

Navigation

Return Home Report An Issue

Dominoes

Dominoes are square tiles often placed near each other to make satisfying effects when it falls and knocks each other over.

You're going to make three Domino processes under a Supervisor (Domino1, Domino2, and Domino3), then have them terminate and restart sequentially.

flowchart
S[Supervisor]
S --> Domino1
S --> Domino2
S --> Domino3
Loading

You should be able to cause each Domino process to crash by sending it a :fall message.

We've created the Domino1 server for sake of example.

defmodule Domino1 do
  use GenServer

  def start_link(state) do
    GenServer.start_link(__MODULE__, state, name: __MODULE__)
  end

  def init(state) do
    {:ok, state}
  end

  def handle_info(:fall, _state) do
    raise "Domino1 falls"
  end
end

Create the Domino2 and Domino3 modules. Then configure them with a supervisor such that each Domino process terminates (and restarts) one after the other.

For example:

  • Domino1 receives the :fall message. Domino1 crashes. Domino2 then Domino3 are terminated by the supervisor.
  • Domino2 receives the :fall message. Domino2 crashes. Domino3 is terminated by the supervisor.
Hint Use the :rest_for_one strategy for your supervisor.

Commit Your Progress

Run the following in your command line from the beta_curriculum folder to track and save your progress in a Git commit.

$ git add .
$ git commit -m "finish dominoes exercise"

Up Next

Previous Next
Supervised Stack Creature Spawner