What does the return value :ignore mean as return value in on_start_child?


DynamicSupervisor — Elixir v1.13.4 it mentions the following return values:

@type on_start_child() ::
  {:ok, pid()}
  | {:ok, pid(), info :: term()}
  | :ignore
  | {:error, {:already_started, pid()} | :max_children | term()}

What does :ignore mean? How should one act on it?

Returning :ignore signals to the supervisor that the process will not be started and that the supervisor should not attempt to start it.

It’s not a value you need to handle or act on — it’s a part of the “contract” with the supervisor.

I meant if the start_child() returns {:ok, pid} or {:error, {:already_started, pid} then I know the process is actually running.
Getting back :ignore, it doesn’t tell me if it is running or not, and couldn’t find it in the docs.

Thx for your reply.

Okay, I see — start_child should only return ignore if the underlying start_link that it calls returns ignore. It means that the process was not and will not be started.

It’s not something you need to handle unless you’ve designed a process that may return :ignore in its own start_link.

In general, Elixir/Erlang type specs enumerate all possible return values, but that doesn’t mean you need to handle them all if you don’t expect them to occur.

1 Like