parallel 1.10.0 → 1.11.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
  SHA1:
3
- metadata.gz: bbf5d8fc78e3bdf6f1d12ae80ffff41fa5e6d0ed
4
- data.tar.gz: c1eb1b447d1c59dce453710d943d2b952d1079b3
3
+ metadata.gz: 7c9109c6823e35d9f0dae9d6b525cd210b050801
4
+ data.tar.gz: 0418fc529365106f7d9915e2c8fb0f223835100d
5
5
  SHA512:
6
- metadata.gz: 0fbe56fc6a4ba0ec2df7bbdb9f16e44b08e42fc0bced3ff939a7baa128940d0afc6ae27da216ffb78dc066f55989e779198cb39137366e6988ab57ba854681cf
7
- data.tar.gz: 1b5252fb4ec4ef143072dbd604641a5d614e16142065f1a1618f665cbc2f74074305adef81e784587ec6a582662bfde67654e0e431850cf9e31dbf0b8082b922
6
+ metadata.gz: 228a5ed608242b00fefe9303ff83cd94b5fd35a338f1657c6a6d21d1cedb53a7a205a31abb838addb8ef1763319ca88556a5435204781aa95ed364345db06ee7
7
+ data.tar.gz: 962275502b4cabd3ddfd3557616e4939520392beae12d665f90d56638f1cd63143a621e6f7e51b2345fd485bfcd4abbe0d3060171ecff9f0626bd75246481768
@@ -199,7 +199,7 @@ module Parallel
199
199
  class << self
200
200
  def in_threads(options={:count => 2})
201
201
  count, _ = extract_count_from_options(options)
202
- Array.new(count).each_with_index.map do |_, i|
202
+ Array.new(count) do |i|
203
203
  Thread.new { yield(i) }
204
204
  end.map!(&:value)
205
205
  end
@@ -212,7 +212,16 @@ module Parallel
212
212
 
213
213
  def each(array, options={}, &block)
214
214
  map(array, options.merge(:preserve_results => false), &block)
215
- array
215
+ end
216
+
217
+ def any?(*args, &block)
218
+ raise "You must provide a block when calling #any?" if block.nil?
219
+ !each(*args) { |*args| raise Parallel::Kill if block.call(*args) }
220
+ end
221
+
222
+ def all?(*args, &block)
223
+ raise "You must provide a block when calling #all?" if block.nil?
224
+ !!each(*args) { |*args| raise Parallel::Kill unless block.call(*args) }
216
225
  end
217
226
 
218
227
  def each_with_index(array, options={}, &block)
@@ -244,13 +253,16 @@ module Parallel
244
253
  options[:return_results] = (options[:preserve_results] != false || !!options[:finish])
245
254
  add_progress_bar!(job_factory, options)
246
255
 
247
- if size == 0
256
+ results = if size == 0
248
257
  work_direct(job_factory, options, &block)
249
258
  elsif method == :in_threads
250
259
  work_in_threads(job_factory, options.merge(:count => size), &block)
251
260
  else
252
261
  work_in_processes(job_factory, options.merge(:count => size), &block)
253
262
  end
263
+ if results
264
+ options[:return_results] ? results : source
265
+ end
254
266
  end
255
267
 
256
268
  def map_with_index(array, options={}, &block)
@@ -295,13 +307,18 @@ module Parallel
295
307
  def work_direct(job_factory, options, &block)
296
308
  self.worker_number = 0
297
309
  results = []
298
- while set = job_factory.next
299
- item, index = set
300
- results << with_instrumentation(item, index, options) do
301
- call_with_index(item, index, options, &block)
310
+ exception = nil
311
+ begin
312
+ while set = job_factory.next
313
+ item, index = set
314
+ results << with_instrumentation(item, index, options) do
315
+ call_with_index(item, index, options, &block)
316
+ end
302
317
  end
318
+ rescue
319
+ exception = $!
303
320
  end
304
- results
321
+ handle_exception(exception, results)
305
322
  ensure
306
323
  self.worker_number = nil
307
324
  end
@@ -322,8 +339,8 @@ module Parallel
322
339
  call_with_index(item, index, options, &block)
323
340
  end
324
341
  results_mutex.synchronize { results[index] = result }
325
- rescue StandardError => e
326
- exception = e
342
+ rescue
343
+ exception = $!
327
344
  end
328
345
  end
329
346
  end
@@ -362,8 +379,8 @@ module Parallel
362
379
  worker.work(job_factory.pack(item, index))
363
380
  end
364
381
  results_mutex.synchronize { results[index] = result } # arrays are not threads safe on jRuby
365
- rescue StandardError => e
366
- exception = e
382
+ rescue
383
+ exception = $!
367
384
  if Parallel::Kill === exception
368
385
  (workers - [worker]).each do |w|
369
386
  w.thread.kill unless w.thread.nil?
@@ -431,8 +448,8 @@ module Parallel
431
448
  item, index = job_factory.unpack(data)
432
449
  result = begin
433
450
  call_with_index(item, index, options, &block)
434
- rescue StandardError => e
435
- ExceptionWrapper.new(e)
451
+ rescue
452
+ ExceptionWrapper.new($!)
436
453
  end
437
454
  Marshal.dump(result, write)
438
455
  end
@@ -1,3 +1,3 @@
1
1
  module Parallel
2
- VERSION = Version = '1.10.0'
2
+ VERSION = Version = '1.11.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.10.0
4
+ version: 1.11.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: 2016-11-24 00:00:00.000000000 Z
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
40
  version: '0'
41
41
  requirements: []
42
42
  rubyforge_project:
43
- rubygems_version: 2.4.5.1
43
+ rubygems_version: 2.5.1
44
44
  signing_key:
45
45
  specification_version: 4
46
46
  summary: Run any kind of code in parallel processes