** (ArgumentError) unknown registry: Req.Finch on a simple http request using Req library

compile-time vs runtime is a pretty broad topic so to just scratch the surface when you have a module:

def Foo do
  IO.puts :at_compile_time

  def foo do
    IO.puts :at_runtime
  end
end

the first IO.puts is executed while the module is being compiled. When it is being used at runtime, that IO.puts will not be executed. On the other hand, the second IO.puts is NOT executed when the module is being compiled. It is only executed when you call Foo.foo(). Doing things at compile-time is definitely an Elixir super power and for this particular use case you need that Application.ensure_all_started. (The reason is Req library starts a supervision tree in its application callback module. If it didn’t, ensure_all_started would not be necessary.) In vast majority of day to day Elixir programming, you don’t need ensure_all_started, it is done for you.

2 Likes