parallel 1.19.2 → 1.20.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5633042712162c3ac1b37b31f546cf70eb45513bc78c2180a5009c8d5a1826a
4
- data.tar.gz: 621b9b2dfa7d8d67494da0ff0ad82c14d67d7e8b11fd73e14fe3b38e7aeaccab
3
+ metadata.gz: fa334cb0d83b8049f260a5e6724d2fd0e65768f85afd0968a2af05d55dda4e0e
4
+ data.tar.gz: 7ba3ade3a7af4bcfe5944b8d7313b5ec6e4074d27755a83f95e4f8a01d77261e
5
5
  SHA512:
6
- metadata.gz: 7de2bb3f72d999e4eacfe84ff8df6ece7d62e60e044ba512fe11d38f2597a53f5c4ccbd0399a9e531184b8e17b25b7671be61d6ef63d739767fcf77bd9808933
7
- data.tar.gz: 76adaacedc029a347231d1690913a2eaccce021e99e80e94a59685a418e617144ad65077d77cc87fd01a3a9cf7a6a4a6250fc2792a3b54f303ef4d99929c4e98
6
+ metadata.gz: d470562bd90ab80c66f69b9c1ab016f737bf52e091ac3027c51ea7482eaecd3bd3c186daab756c5d4276b9fb54f0e80f149a8071dc17c31a321ff4fc4d369600
7
+ data.tar.gz: f01bf1c3a052579c11c3097b02b02a4a30c8e881dbb4916c3ceba6f122aab3a40c276a1de82f7ea7d3790eeff2f994bd20283361151439a3d57b025bdd24dfc8
@@ -3,15 +3,21 @@ require 'parallel/version'
3
3
  require 'parallel/processor_count'
4
4
 
5
5
  module Parallel
6
- extend Parallel::ProcessorCount
6
+ extend ProcessorCount
7
+
8
+ Stop = Object.new.freeze
7
9
 
8
10
  class DeadWorker < StandardError
9
11
  end
10
12
 
11
13
  class Break < StandardError
14
+ attr_reader :value
15
+ def initialize(value = nil)
16
+ @value = value
17
+ end
12
18
  end
13
19
 
14
- class Kill < StandardError
20
+ class Kill < Break
15
21
  end
16
22
 
17
23
  class UndumpableException < StandardError
@@ -22,8 +28,6 @@ module Parallel
22
28
  end
23
29
  end
24
30
 
25
- Stop = Object.new.freeze
26
-
27
31
  class ExceptionWrapper
28
32
  attr_reader :exception
29
33
  def initialize(exception)
@@ -102,7 +106,7 @@ module Parallel
102
106
  item, index = @mutex.synchronize do
103
107
  return if @stopped
104
108
  item = @lambda.call
105
- @stopped = (item == Parallel::Stop)
109
+ @stopped = (item == Stop)
106
110
  return if @stopped
107
111
  [item, @index += 1]
108
112
  end
@@ -230,12 +234,12 @@ module Parallel
230
234
 
231
235
  def any?(*args, &block)
232
236
  raise "You must provide a block when calling #any?" if block.nil?
233
- !each(*args) { |*a| raise Parallel::Kill if block.call(*a) }
237
+ !each(*args) { |*a| raise Kill if block.call(*a) }
234
238
  end
235
239
 
236
240
  def all?(*args, &block)
237
241
  raise "You must provide a block when calling #all?" if block.nil?
238
- !!each(*args) { |*a| raise Parallel::Kill unless block.call(*a) }
242
+ !!each(*args) { |*a| raise Kill unless block.call(*a) }
239
243
  end
240
244
 
241
245
  def each_with_index(array, options={}, &block)
@@ -270,16 +274,18 @@ module Parallel
270
274
  options[:return_results] = (options[:preserve_results] != false || !!options[:finish])
271
275
  add_progress_bar!(job_factory, options)
272
276
 
273
- results = if size == 0
274
- work_direct(job_factory, options, &block)
275
- elsif method == :in_threads
276
- work_in_threads(job_factory, options.merge(:count => size), &block)
277
- else
278
- work_in_processes(job_factory, options.merge(:count => size), &block)
279
- end
280
- if results
281
- options[:return_results] ? results : source
282
- end
277
+ result =
278
+ if size == 0
279
+ work_direct(job_factory, options, &block)
280
+ elsif method == :in_threads
281
+ work_in_threads(job_factory, options.merge(:count => size), &block)
282
+ else
283
+ work_in_processes(job_factory, options.merge(:count => size), &block)
284
+ end
285
+
286
+ return result.value if result.is_a?(Break)
287
+ raise result if result.is_a?(Exception)
288
+ options[:return_results] ? result : source
283
289
  end
284
290
 
285
291
  def map_with_index(array, options={}, &block)
@@ -340,7 +346,7 @@ module Parallel
340
346
  rescue
341
347
  exception = $!
342
348
  end
343
- handle_exception(exception, results)
349
+ exception || results
344
350
  ensure
345
351
  self.worker_number = nil
346
352
  end
@@ -367,7 +373,7 @@ module Parallel
367
373
  end
368
374
  end
369
375
 
370
- handle_exception(exception, results)
376
+ exception || results
371
377
  end
372
378
 
373
379
  def work_in_processes(job_factory, options, &blk)
@@ -401,7 +407,7 @@ module Parallel
401
407
  results_mutex.synchronize { results[index] = result } # arrays are not threads safe on jRuby
402
408
  rescue StandardError => e
403
409
  exception = e
404
- if Parallel::Kill === exception
410
+ if Kill === exception
405
411
  (workers - [worker]).each do |w|
406
412
  w.thread.kill if w.thread
407
413
  UserInterruptHandler.kill(w.pid)
@@ -414,8 +420,7 @@ module Parallel
414
420
  end
415
421
  end
416
422
  end
417
-
418
- handle_exception(exception, results)
423
+ exception || results
419
424
  end
420
425
 
421
426
  def replace_worker(job_factory, workers, i, options, blk)
@@ -484,12 +489,6 @@ module Parallel
484
489
  end
485
490
  end
486
491
 
487
- def handle_exception(exception, results)
488
- return nil if [Parallel::Break, Parallel::Kill].include? exception.class
489
- raise exception if exception
490
- results
491
- end
492
-
493
492
  # options is either a Integer or a Hash with :count
494
493
  def extract_count_from_options(options)
495
494
  if options.is_a?(Hash)
@@ -1,3 +1,3 @@
1
1
  module Parallel
2
- VERSION = Version = '1.19.2'
2
+ VERSION = Version = '1.20.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.2
4
+ version: 1.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-17 00:00:00.000000000 Z
11
+ date: 2020-11-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it
@@ -25,8 +25,8 @@ licenses:
25
25
  - MIT
26
26
  metadata:
27
27
  bug_tracker_uri: https://github.com/grosser/parallel/issues
28
- documentation_uri: https://github.com/grosser/parallel/blob/v1.19.2/Readme.md
29
- source_code_uri: https://github.com/grosser/parallel/tree/v1.19.2
28
+ documentation_uri: https://github.com/grosser/parallel/blob/v1.20.1/Readme.md
29
+ source_code_uri: https://github.com/grosser/parallel/tree/v1.20.1
30
30
  wiki_uri: https://github.com/grosser/parallel/wiki
31
31
  post_install_message:
32
32
  rdoc_options: []
@@ -36,7 +36,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '2.2'
39
+ version: '2.4'
40
40
  required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ">="