parallel 1.19.2 → 1.20.0

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: 1f41f840e7e5128ebbb8d4ea2955b5bc555925ac049184ae1d4323885a3980b9
4
+ data.tar.gz: f9463997e0b890857d1909e6df6c8632b08eb028fc4015541631ca275d1fabfb
5
5
  SHA512:
6
- metadata.gz: 7de2bb3f72d999e4eacfe84ff8df6ece7d62e60e044ba512fe11d38f2597a53f5c4ccbd0399a9e531184b8e17b25b7671be61d6ef63d739767fcf77bd9808933
7
- data.tar.gz: 76adaacedc029a347231d1690913a2eaccce021e99e80e94a59685a418e617144ad65077d77cc87fd01a3a9cf7a6a4a6250fc2792a3b54f303ef4d99929c4e98
6
+ metadata.gz: '0581d59c3d38af4fefdd761264899f9661a3c28e8a4d3c9683f7e93c2295313e53d518263a6b4d04fcbb9a57eb55dfe3854e8c27f9f4e378641823eea2aada72'
7
+ data.tar.gz: f77d00250586ada81bddfc2dd47e4895a526215549cee3728f31a927dd617a3a4d2bca7e72d9c7ff3c481e3a4488933c490153d0ef7dec97dc6a5cdd6bc513ed
@@ -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.0'
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.0
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-07 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.0/Readme.md
29
+ source_code_uri: https://github.com/grosser/parallel/tree/v1.20.0
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.5'
40
40
  required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ">="