parallel_worker
Run a processing block in parallel fibers/processes.
Installation
-
Add the dependency to your
shard.yml
:dependencies: parallel_worker: github: aligo/parallel_worker
-
Run
shards install
Usage
require "parallel_worker"
# Pass all 0..256 one by one to block, running in 4 fiber workers, then resulting a Array(String) as return
worker = ParallelWorker::Fiber(Int32, String).new(4) do |input_int|
input_int.to_s
end
results = worker.perform_all (0..256).to_a
# Or run the block in 2 processes
worker = ParallelWorker::Process(Int32, String).new(2) do |input_int|
input_int.to_s
end
results = worker.perform_all (0..256).to_a
Contributing
- Fork it (https://github.com/aligo/parallel_worker/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request