RpcElixir.Watcher (elixir_ts_rpc v0.0.1)

Copy Markdown View Source

Dev-only GenServer that watches every source file contributing to an RPC router — the router module itself and every handler module — and triggers recompilation when one of them changes.

Requires the optional :file_system dep. If it is not loaded, init/1 returns :ignore — the process is never started — after emitting a warning.

This watcher is Phoenix-specific: without an :endpoint or :on_change option there is nothing to do when a file changes. For non-Phoenix apps the Mix.Tasks.Compile.ElixirTsRpc compiler already regenerates the TypeScript client on each Elixir recompile; you do not need this watcher.

Usage

# lib/my_app/application.ex  (Phoenix projects only)
children = [
  # …
  {RpcElixir.Watcher, router: MyApp.Router, endpoint: MyAppWeb.Endpoint}
]

Options

  • :router (required) — the RPC router module.
  • :endpoint — a Phoenix endpoint; the watcher calls Phoenix.CodeReloader.reload/1 on each relevant change.
  • :on_change{mod, fun, args} invoked on change. Takes precedence over :endpoint when both are given.
  • :debounce_ms — milliseconds to coalesce rapid file events before triggering a reload. Defaults to 200.

Restart expectations

RpcElixir.Watcher traps exits so that it can clean up on supervisor shutdown. The linked FileSystem process is started inside init/1; if it crashes unexpectedly the watcher will also terminate and the supervisor is expected to restart the pair.

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)