ConditionalChild - Start and stop processes conditionally (e.g. via feature flags)

Announcing a tiny library called Conditional Child, that allows you to define directly in your supervision tree a condition for when a process should run. The condition is checked periodically, so it allows you to toggle processes in runtime.

A common use case is to manage processes using feature flags, but any condition can be used.


defmodule Demo.Application do
  @moduledoc false

  use Application

  @impl true
  def start(_type, _args) do
    children = [
      {ConditionalChild, child: Demo.Worker, start_if: fn -> your_condition() end}

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


1 Like

That looks pretty handy, particularly during the development cycle where running internal “services” make a mess of the logs.