ExCodecs.Application (ex_codecs v0.2.1)

Copy Markdown View Source

OTP Application callback module for ExCodecs.

Starts the shared ExCodecs.CodecRegistry catalog and registers all built-in binary and spatial codecs during application startup.

Summary

Functions

Starts the ExCodecs supervision tree.

Functions

start(type, args)

@spec start(Application.start_type(), term()) ::
  {:ok, pid()} | {:error, term()} | {:ok, pid(), term()}

Starts the ExCodecs supervision tree.

This callback starts ExCodecs.CodecRegistry, registers every built-in codec entry, and supervises the registry with a :one_for_one strategy. It is invoked by OTP when the :ex_codecs application starts; application code should normally use Application.ensure_all_started/1 instead of calling this function directly.

Arguments

  • typeApplication.start_type(). OTP supplies :normal, {:takeover, node}, or {:failover, node}; ExCodecs does not vary its startup behavior by type.
  • args — startup term configured for the application. ExCodecs ignores this value.

Returns

  • {:ok, supervisor_pid} when the supervisor and registry start.
  • {:error, reason} when Supervisor.start_link/2 cannot start the supervision tree.
  • {:ok, supervisor_pid, state} is permitted by the Application.start/2 callback contract, but ExCodecs does not currently return that form.

Raises

This callback does not deliberately raise. OTP or supervisor internals may exit the calling process for unrecoverable startup failures.

Example

iex> {:ok, _apps} = Application.ensure_all_started(:ex_codecs)
iex> Process.whereis(ExCodecs.Supervisor) |> is_pid()
true
iex> ExCodecs.supports?(:zstd)
true

Callback implementation

An OTP application that embeds a similar registry can use the same shape:

defmodule MyApp.Application do
  use Application

  @impl Application
  def start(_type, _args) do
    children = [{ExCodecs.CodecRegistry, register: fn -> :ok end}]
    Supervisor.start_link(children,
      strategy: :one_for_one,
      name: MyApp.Supervisor
    )
  end
end