0.01
No commit activity in last 3 years
No release in over 3 years
`make -j4` -like parallel execution
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0
>= 0
 Project Readme

This library lets you have a bunch of inter-dependent tasks run in parallel, but not all together. Much like make -j4 runs at most 4 tasks at once.

Detailed usage

This library has only one intuitive usage. First create a SizedParallel instance.

sp = SizedParallel.new 65535

Omit the argument to use the active CPU count (default).

Then add your series of jobs.

128.times {
  sp.start {
      Resolv.getaddress 'www.ruby-lang.org'
  }.then { |addr|
      Net::HTTP.get addr, '/'
  }.then { |html|
      Nokogiri::HTML html
  }
}

In the example above 128 concurrent name resolution are registered. Then for each resolved address, HTTP query is registered (in parallel). And lastly the response HTML is registered to parse (also in parallel).

Those jobs are not triggered yet. In order to do so you call a wait for the object.

sp.wait

This blocks, until all the registered jobs finish either gracefully or unexpectedly.

Restrictions

This library is written in pure ruby so ultra portable by nature, but requires at least version 2.2 or higher (or compatible alternatives) because Etc.nproessors is mandatory.