Skip to main content

Module worker

Module worker 

Source
Expand description

Generic rebuild-worker driver for dev servers.

Spawns a background OS thread that owns the rebuild loop:

  1. Block waiting for a tick.
  2. Drain any extra ticks queued before the thread woke up — they coalesce into a single rebuild.
  3. Run the user-supplied rebuild closure.
  4. Drain any ticks that arrived during the rebuild — if any did, re-tick ourselves so the next iteration runs without waiting.
  5. Report success / error via RebuildReporter and broadcast the corresponding live-reload event.

The closure is the only thing that varies between consumers (webui-cli builds and renders an app, webui-press rebuilds a docs site). It returns Result<(), String> so the worker can uniformly format the error and broadcast it to connected browsers.

Functions§

spawn_rebuild_worker
Spawn the rebuild worker on a dedicated OS thread and return the sender used to enqueue rebuild ticks. The watcher closure should call tx.try_send(()) for every filesystem event burst — failed sends (channel full) are intentional coalescing.

Type Aliases§

TickSender
Tick sender given to the watcher closure. Cheap to clone.