Skip to main content

spawn_rebuild_worker

Function spawn_rebuild_worker 

Source
pub fn spawn_rebuild_worker<F>(livereload: LiveReload, rebuild: F) -> TickSender
where F: FnMut() -> Result<Vec<String>, RebuildError> + Send + 'static,
Expand description

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(paths) with the changed paths for every filesystem event burst — failed sends (channel full) are intentional coalescing.

The closure runs synchronously on the worker thread, so it may use blocking I/O freely. It returns Ok(warnings) on success (a possibly-empty list of plain, color-free advisory lines to print under the rebuild line) or Err(RebuildError) on failure; the worker prints the error’s terminal rendering and broadcasts its plain message to connected browsers.

The returned TickSender does not need to be held to keep the worker alive — the worker stops only when every clone of the sender is dropped.