module

Hwaro::Core::Build::ParallelHelper

Convenience methods for common parallel operations

Instance methods

each_concurrently(items : Array(T), workers : Int32, &block : T, Int32 -> ) : Nil forall T

Run block once per item on workers fibers pulling from a shared queue; the block also gets the worker's index (0...workers) so it can use per-worker state. Returns once every item has been handled. Callers rescue inside the block: an exception that escapes it still signals its item (from an ensure) but ends that worker fiber.

Source
execute(tasks : Array(Proc(Nil)), parallel : Bool = true, raise_on_error : Bool = true)

Execute multiple independent tasks in parallel.

raise_on_error: true (default) surfaces the first task failure once every task has drained — sequential mode lets a task exception abort the build, and parallel mode used to swallow it behind a warning, so e.g. a failed sitemap/feed generator still exited 0 and CI shipped a site missing those files. Generic exceptions are promoted to a classified HwaroError (mirroring #490 in process_files_parallel): the lifecycle turns unclassified phase exceptions into a silent HookResult::Abort where --json still reports status "ok".

Serve-time callers that must stay resilient across a transient generator failure (the watch/fast-start passes, where a raise would skip cache persistence and the live-reload signal) pass raise_on_error: false to keep the warn-and-continue behavior.

Source
map(items : Array(T), parallel : Bool = true, &block : T -> R) : Array(R) forall T, R

Parallel map with default configuration

Source
wake_idle_threads=(value : Bool) : Nil

hwaro build turns this on. serve keeps the stock scheduling: a wake also pulls the thread waiting on the event loop into the workers, and serve must keep answering HTTP during a rebuild.

Source
wake_workers(count : Int32) : Nil

Wake idle threads to run fibers this fiber just spawned; see src/ext/execution_context_wake.cr. Called after spawning the workers, and only for the wake_idle fan-outs (OG images, image resizing): woken threads make completion order vary on every build, which the others' first-error pick and warning order would show.

Source