0.0
No commit activity in last 3 years
No release in over 3 years
Launch an array of Procs within threads.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0
>= 0
 Project Readme

ThreadifyProcs

Build Status

Create an array of Procs, launch them within threads. It adresses the common problem of writting files concurrently in threads with a ruby proces or downloading simultaneously multiple files. It avoids 'Too many open files' errors.

Usage

require 'threadify_procs'
procs = [
  Proc.new { puts 1 },
  Proc.new { puts 2 }
]
call_with_threads procs, number_of_threads: 50

An other option is available :with_writer (boolean). Its goal is to launch another thread which responsibility is to create files on disc.

require 'threadify_procs'
procs = []
10_000.times do |n|
  Proc.new do
    @files_to_write << [
      "#{Rails.root}/tmp/#{n}.txt", SecureRandom.uuid]
  end
end
launch_in_threads procs, number_of_threads: 50, with_writer: true

You can also use the callback option with a proc. It will be called after all the threads are finished.

launch_in_threads procs, number_of_threads: 50, callback: Proc.new { function_to_be_called }