module

Parallel

Core module for parallel processing functionality

Constants

VERSION = {{ (`shards version /tmp/tmp.CJFFdJ/src/src/parallel`).chomp.stringify }}

Class methods

adaptive_chunk_size(collection_size : Int32) : Int32

Determines optimal chunk size for adaptive chunking. The computed size is clamped to 1..1000.

Source
check_empty_and_size(collection) : Tuple(Bool, Int32)

Unified empty check for collections Returns {is_empty, estimated_size}

Source
execution_context

Returns the current default context. Lazily creates a dedicated context.

Source

Sets the default context explicitly.

Source
log_fiber_exception(ex : Exception, task_info : String | Nil = nil)

Logs fiber exceptions with context information

Source
parallel_each(collection_size : Int32, context : Fiber::ExecutionContext::Parallel, chunk_size : Int32, &block : Int32 -> _)

Common parallel each implementation This method handles the core logic for both Enumerable and Indexable versions

Source
parallel_each_enumerable(enumerable : Enumerable(T), context : Fiber::ExecutionContext::Parallel, chunk_size : Int32, &block : T -> _) forall T

Lazy parallel each implementation for Enumerable collections This method processes elements without materializing the entire collection Uses lock-free work-stealing approach for better performance

Source
parallel_map_enumerable(enumerable : Enumerable(T), context : Fiber::ExecutionContext::Parallel, chunk_size : Int32, &block : T -> U) forall T, U

Common parallel map implementation for Enumerable collections using lazy evaluation This method handles the core logic for Enumerable versions without creating intermediate arrays Uses lock-free work-stealing approach for better performance

Source
parallel_map_indexable(collection_size : Int32, context : Fiber::ExecutionContext::Parallel, chunk_size : Int32, &block : Int32 -> U) forall U

Common parallel map implementation for Indexable collections This method handles the core logic for Indexable versions using direct index access

Source
validate_chunk_size(chunk : Int32 | Nil, collection_size : Int32) : Int32

Validates and normalizes chunk size parameter Returns the validated chunk size or raises an exception for invalid values

Source