# `mix dala.watch`
[🔗](https://github.com/manhvu/dala_dev/blob/main/lib/mix/tasks/dala.watch.ex#L1)

Watches `lib/` for source changes and automatically compiles + hot-pushes
updated modules to all running Android and iOS devices.

Apps must already be running. Modules are loaded in place — no restart.
Only modules that actually changed are pushed each cycle.

Press Ctrl-C to stop.

Options:
  --cookie        Erlang cookie (default: dala_secret)
  --debounce      ms to wait after a change before compiling (default: 300)
  --interval      ms between file-change polls (default: 500)

Examples:
    mix dala.watch
    mix dala.watch --debounce 500
    mix dala.watch --cookie my_cookie

## Under the hood

`mix dala.watch` is an mtime-polling file watcher that drives `mix compile` and
`nl/1` in a loop:

    # On startup:
    writes OS PID → _build/dala_watch.pid    # used by mix dala.watch_stop

    # Each cycle (every --interval ms):
    snapshot mtimes of lib/**/*.ex
    if any changed:
      :timer.sleep(debounce_ms)             # wait for format-on-save to settle
      System.cmd("mix", ["compile"])        # compile in a subprocess
      for each changed BEAM, on each node:
        :rpc.call(node, :code, :load_binary, [...])

Compile runs in a subprocess (not `Mix.Task.run("compile")` so that Mix's
task cache won't prevent recompilation on subsequent file saves.

The watch loop is equivalent to running `mix compile && nl(ChangedModule)` in
a terminal after every save — `mix dala.watch` just does it automatically.

# `pid_file`

```elixir
@spec pid_file() :: String.t()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
