difference between worker and supervisor elixir apps

Viewed 1442

I'm very new on elixir/phoenix. I'm working on an previously created app that have multiples repositories and today I see an example that makes me wonder what means that configuration

I think I dont know how to search that is the reason I can't find the right answer on documentation

first the app I'm working have something like

defmodule RestApi do
  use Application

  def start(_type, _args) do
    import Supervisor.Spec, warn: false

    children = [
      supervisor(RestApi.Endpoint, []),
      supervisor(RestApi.Repo, []),]),
      supervisor(RestApi.OtherRepo, []),]),
    ]

    opts = [strategy: :one_for_one, name: RestApi.Supervisor]
    Supervisor.start_link(children, opts)
  end

  def config_change(changed, _new, removed) do
    RestApi.Endpoint.config_change(changed, removed)
    :ok
  end
end

they use the function Supervisor.Spec.supervisor/3 to start/manage everything

later I found an example

defmodule RestApi do
  use Application

  def start(_type, _args) do
    import Supervisor.Spec, warn: false

    children = [
      supervisor(RestApi.Endpoint, []),
      worker(RestApi.Repo, []),
    ]

    opts = [strategy: :one_for_one, name: RestApi.Supervisor]
    Supervisor.start_link(children, opts)
  end

  def config_change(changed, _new, removed) do
    RestApi.Endpoint.config_change(changed, removed)
    :ok
  end
end

in the example they use Supervisor.Spec.worker/3 to start/manage the repo

What is the difference on this? I mean how affects the app (performance, memory consumption, etc)

2 Answers
Related