Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

08112022 Supervisors - Questions aplenty #18

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

BigSpaces
Copy link
Owner

Hello @BrooklinJazz,

Several points of mental blocks during the Supervisors exercises.

Question 1: On the Supervised Stack exercise, this is how I first tried to start the supervisor. I don't know what I am doing, really...

children = [%{id: :stack, start: {__MODULE__, :start_link, []}}]
Supervisor.start_link(children, strategy: :one_for_one)

Question 2:
I think I am not grasping the start signature. I do not understand the different parameters or arguments. I feel I am shooting in the dark when creating one. Guidance, please? There are several instances during the exercises in which I fail to grock that first step. Examples:

def start_link(opts) do
    IO.inspect(opts, label: "STARTED DOMINO")
    GenServer.start_link(__MODULE__, opts, name: opts[:name])
  end

Why name: opts[:name] - My brain does not know when we use opts or how

children = [
  %{
    id: :domino1,
    start: {Domino, :start_link, [[name: :domino1]]}
  },
  %{
    id: :domino2,
    start: {Domino, :start_link, [[name: :domino2]]}
  },
  %{
    id: :domino3,
    start: {Domino, :start_link, [[name: :domino3]]}
  }
]

{:ok, supervisor_pid} = Supervisor.start_link(children, strategy: :rest_for_one)

Again I do not understand the start signature [[name: :domino3]]

Question 3:

My implementation of the dying monster does not work... Here is your implementation and mine down below (commented)

 @impl true
  def handle_cast({:attack, damage}, state) do
    new_health = state.health - damage

    if new_health <= 0 do
      raise "dying!"
    else
      {:noreply, %{state | health: new_health}}
    end
  end
   # BrookQuestion - Why is my implementation not working? I don't get it:   

    # case state.health - damage do
    #   0 ->
    #     raise("Morir! Morir!")

    #   true ->
    #     new_state = Map.replace(state, :health, state.health - damage)
    #     {:noreply, new_state}
    # end

Thank you Brook!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant