parallax 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 199b9a1f7d00f3ab396af10da44fbec350f059444e133a68128c33f6103efd44
4
- data.tar.gz: f23cd123597d3070c5e23ab98a5db1288c5d85bf0f4170618ff304a1f17e05e9
3
+ metadata.gz: 8550cb7115815b07ee890e22a8d9df2c956b8f7ed4c8d6b3e72cfbcb7045926c
4
+ data.tar.gz: ab4ce11646317867bc4aca9e6a14b8877255afddc3bb7486831e3522feae7576
5
5
  SHA512:
6
- metadata.gz: a6a57b1760de4e0e857f46e2da3d0c18040846358c5f398270ec33328e661e63bff3d68d6a6d91baf09b38eb209a73691a14b3294b8aa58870847dac66084018
7
- data.tar.gz: 6b8a58e098e65c5070b804cc6081dce58f616aaf06bd6b25adadb2cc2db8e5bf1606fa75732ef4fe0f73c9f98ba0f97c87ee6dc1fd8ec7c4d469bc3549edb7bc
6
+ metadata.gz: 62c77b06eb45b8ddfa0142c962d808ece8a44f41d39d7ec942ab320c59213b32fa83b814dc69b7095e8654b28d7f724046b53830dabd1fb58d9ce6823d00e6ac
7
+ data.tar.gz: b9def74a52b5ec5132ec7bd26c28aeacecb33cfee4147c6281b5d59f31795cbb476c2f87fc35b89d16bde9be05ea9565848efef2cff1e568100fd76b2cfb074c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parallax (0.3.0)
4
+ parallax (0.3.1)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -71,21 +71,21 @@ Other options you can pass to execute are:
71
71
  * `processes`: the number of processes in which parallelize the execution. Defaults to `Etc.nprocessors` (which is equal to the number of cores of the current running machine).
72
72
  * `collector`: a custom collector object that you can implement yourself.
73
73
 
74
- To use a custom collector, you need to `include Parallax::Collectable` in your custom collector, and initialize your collector by calling the included `initialize_collector` method.
75
- Example of a custom collector:
74
+ To use a custom collector, you need to `include Parallax::Collectable` in your custom collector. Example of a custom collector:
76
75
 
77
76
  ```ruby
78
77
  # custom_collector.rb
79
78
  class CustomCollector
80
79
  include Parallax::Collectable
81
80
 
82
- def initialize(worker_count, *args)
83
- # Do your own initialization with *args, and then
84
- initialize_collector(workers_count)
81
+ attr_accessor :name
82
+
83
+ def initialize(name)
84
+ @name = name
85
85
  end
86
86
 
87
87
  def store(worker_index, object)
88
- workers_data.push [ "worker #{worker_index} stored: #{object.inspect}" ]
88
+ workers_data.push "#{self.name}: worker #{worker_index} stored: #{object}"
89
89
  end
90
90
  end
91
91
  ```
@@ -94,7 +94,7 @@ end
94
94
  workers_count = 4
95
95
  numbers = (0..100).to_a
96
96
 
97
- custom_collector = CustomCollector.new(workers_count)
97
+ custom_collector = CustomCollector.new('custom_collector')
98
98
  Parallax.execute numbers, collector: custom_collector, do |worker, numbers_chunk|
99
99
  numbers_chunk.each do |number|
100
100
  worker.store number * 2
@@ -104,10 +104,10 @@ end
104
104
  puts custom_collector.workers_data.inspect
105
105
 
106
106
  # Example output with 4 cores and custom collector:
107
- # [ ["worker 0 stored 0"],
108
- # ["worker 3 stored 152"],
109
- # ["worker 1 stored 52"],
110
- # ["worker 2 stored 102"],
107
+ # [ "custom_collector: worker 0 stored 0",
108
+ # "custom_collector: worker 3 stored 152",
109
+ # "custom_collector: worker 1 stored 52",
110
+ # "custom_collector: worker 2 stored 102",
111
111
  # ...
112
112
  ```
113
113
 
@@ -19,12 +19,13 @@ module Parallax
19
19
  #
20
20
  # @param [Integer] workers_count the number of workers running in parallel.
21
21
  #
22
- # @return [nil]
22
+ # @return [Object] the instance of the including object.
23
23
  def initialize_collector(workers_count)
24
24
  @workers_count = workers_count
25
25
  @closed_workers_count = 0
26
26
  @receiving_stream, @sending_stream = IO.pipe
27
27
  @workers_data = []
28
+ self
28
29
  end
29
30
 
30
31
  ##
@@ -1,3 +1,3 @@
1
1
  module Parallax
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
data/lib/parallax.rb CHANGED
@@ -9,14 +9,6 @@ module Parallax
9
9
 
10
10
  class << self
11
11
 
12
- ##
13
- # Get the default number of workers.
14
- #
15
- # @return [Integer] the workers count.
16
- def workers_count
17
- Etc.nprocessors
18
- end
19
-
20
12
  ##
21
13
  # Divides the given elements in groups of N and executes
22
14
  # each chunk in parallel with the given block.
@@ -26,10 +18,10 @@ module Parallax
26
18
  #
27
19
  # @return [Collector] all processes output collector.
28
20
  def execute(elements, options = {}, &block)
29
- processes = options[:processes] || Parallax.workers_count
21
+ processes = options[:processes] || Etc.nprocessors
30
22
 
31
23
  if options[:collector].present?
32
- collector = options[:collector]
24
+ collector = options[:collector].initialize_collector(processes)
33
25
  else
34
26
  collector = Parallax::Collector.new(processes)
35
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Ballardin