Parallel

test Lines of Code

Crystal library for parallel processing using Fiber::ExecutionContext.

Requirements

Installation

Add to shard.yml:

dependencies:
  parallel:
    github: kojix2/parallel

Run shards install

Usage

require "parallel"

# Parallel map
[1, 2, 3, 4].par_map { |x| x * 2 }
# => [2, 4, 6, 8]

# Parallel each
[1, 2, 3, 4].par_each { |x| puts x }

# Chunk processing (fewer context switches)
[1, 2, 3, 4].par_map(chunk: 2) { |x| x * 2 }
# => [2, 4, 6, 8] (same result, better performance)

# Custom ExecutionContext
context = Fiber::ExecutionContext::MultiThreaded.new("workers", 8)
[1, 2, 3, 4].par_map(context) { |x| x * 2 }

Compilation

crystal build -Dpreview_mt -Dexecution_context your_app.cr
crystal spec -Dpreview_mt -Dexecution_context

Methods

Notes

Contributing

License

MIT

This library contains code generated by AI.