in_threads 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 55a72b765291c267b859530ea8413d70201e45fc
4
- data.tar.gz: 2227981ac7e0ed5c3e4b3a438a6087acfe427504
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Mzk1MDRlMTMzNjc1OTBjMzIyYzA3ZTEyNTdlODk4NmM1ZjAzOTkzNA==
5
+ data.tar.gz: !binary |-
6
+ ZGM4ZTQ3N2YxM2M4NTgxODNiNWUzMTc1NWE5MjJlYWQ0MjE2NTY5Yw==
5
7
  SHA512:
6
- metadata.gz: 6eb1d9590ba97d801053e963772bdf69411e7b08c44c11c31f149ca71d2b0919b64bf07c7c73bda2748e17a99faa9abb3853bea7b161013c84c9b81336d466ba
7
- data.tar.gz: dd1fa2f4e0d304a9f4f6a0ea33379fad3a28937f8d9e008e40e2e954a8d36ce613f3102d0259fd69154b4016045ac9cfed140f006235d5166d6b329bcc892e98
8
+ metadata.gz: !binary |-
9
+ MGQwMjZiZjU1NmE2NTVkYzdjOTU1OWMzNDA0MDkxNjFkNzQwOTNkZDAwYmQy
10
+ OWRkODZkMWE0ZTFmZjU0YjNhY2YyNjQyNmI2MDFkOGE2Y2FlOTIxNzU1ZWUx
11
+ Zjc1ZDE0NGI5Mjg1MjcxNTgyMmI4NWVkM2UyMTg4NDhjZDExMDc=
12
+ data.tar.gz: !binary |-
13
+ OGFmODBhMDljYzNjZDdmYmI5YjBhNmI0NzA4NzgxYTk4OTUwODM5YThhNmQ0
14
+ MDAzMGU2ZTIwNGU4ZjlmNGZjNDBjNjgxNTZhMTA2NzAwZWJhODQyNDFlODlj
15
+ YzYyZWIwYjUyOGUzM2ExMGNhOTIwZmI5NWEzODBlN2E2YWU2OTY=
data/.rubocop.yml CHANGED
@@ -5,6 +5,9 @@ AllCops:
5
5
  Lint/EndAlignment:
6
6
  AlignWith: variable
7
7
 
8
+ Metrics/AbcSize:
9
+ Max: 25
10
+
8
11
  Metrics/ClassLength:
9
12
  Max: 150
10
13
 
data/.travis.yml CHANGED
@@ -3,18 +3,20 @@ rvm:
3
3
  - 1.8.7
4
4
  - 1.9.2
5
5
  - 1.9.3
6
- - 2.0.0
7
- - 2.1.0
8
- - ruby-head
6
+ - '2.0'
7
+ - '2.1'
8
+ - '2.2'
9
9
  - jruby-18mode
10
10
  - jruby-19mode
11
- - jruby-head
12
11
  - ree
13
12
  script:
14
- - bundle exec rspec
15
- - '! bundle show rubocop || bundle exec rubocop' # run rubocop only if bundled
13
+ if [ -z "$RUBOCOP" ]; then
14
+ bundle exec rspec
15
+ ; else
16
+ bundle exec rubocop
17
+ ; fi
16
18
  matrix:
17
19
  fast_finish: true
18
- allow_failures:
19
- - rvm: ruby-head
20
- - rvm: jruby-head
20
+ include:
21
+ - env: RUBOCOP=true
22
+ rvm: default
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2014 Ivan Kuchin
1
+ Copyright (c) 2010-2015 Ivan Kuchin
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -38,4 +38,4 @@ You can use any Enumerable method, but some of them can not use threads (`inject
38
38
 
39
39
  ## Copyright
40
40
 
41
- Copyright (c) 2010-2014 Ivan Kuchin. See LICENSE.txt for details.
41
+ Copyright (c) 2010-2015 Ivan Kuchin. See LICENSE.txt for details.
data/in_threads.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'in_threads'
5
- s.version = '1.3.0'
5
+ s.version = '1.3.1'
6
6
  s.summary = %q{Execute ruby code in parallel}
7
7
  s.homepage = "http://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
@@ -16,7 +16,8 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = %w[lib]
17
17
 
18
18
  s.add_development_dependency 'rspec', '~> 3.0'
19
+ s.add_development_dependency 'rspec-retry', '~> 0.3'
19
20
  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('1.9.3')
20
- s.add_development_dependency 'rubocop', '~> 0.26.0'
21
+ s.add_development_dependency 'rubocop', '~> 0.26'
21
22
  end
22
23
  end
data/lib/in_threads.rb CHANGED
@@ -179,16 +179,17 @@ class InThreads < SimpleDelegator
179
179
  collect map group_by max_by min_by minmax_by sort_by
180
180
  flat_map collect_concat
181
181
  ], :ignore_undefined => true
182
- use :run_without_threads, :for => %w[
182
+
183
+ INCOMPATIBLE_METHODS = %w[
183
184
  inject reduce
184
185
  max min minmax sort
185
- entries to_a to_set
186
+ entries to_a to_set to_h
186
187
  drop take
187
188
  first
188
189
  include? member?
189
190
  each_with_object
190
- chunk slice_before
191
- ], :ignore_undefined => true
191
+ chunk slice_before slice_after slice_when
192
+ ].map(&:to_sym)
192
193
 
193
194
  # Special case method, works by applying `run_in_threads_consecutive` with
194
195
  # map on enumerable returned by blockless run
@@ -249,9 +250,4 @@ protected
249
250
  enumerable.send(method, *args)
250
251
  end
251
252
  end
252
-
253
- # Use for methods which don't use blocks or can not use threads
254
- def run_without_threads(method, *args, &block)
255
- enumerable.send(method, *args, &block)
256
- end
257
253
  end
@@ -67,16 +67,6 @@ class RandItem < ValueItem
67
67
  end
68
68
  end
69
69
 
70
- # Create custom Enumerables
71
- module CustomEnum
72
- def self.new(&block)
73
- Class.new do
74
- include Enumerable
75
- define_method :each, &block
76
- end.new
77
- end
78
- end
79
-
80
70
  class TestException < StandardError; end
81
71
 
82
72
  def describe_enum_method(method, &block)
@@ -172,11 +162,7 @@ describe 'in_threads' do
172
162
  describe 'underlying enumerable usage' do
173
163
  %w[each map all?].each do |method|
174
164
  it "should call underlying enumerable.each only once for #{method}" do
175
- enum = CustomEnum.new do |&block|
176
- 100.times.each do |i|
177
- block[ValueItem.new(i, i < 50)]
178
- end
179
- end
165
+ enum = 100.times.map{ |i| ValueItem.new(i, i < 50) }
180
166
 
181
167
  expect(enum).to receive(:each).once.and_call_original
182
168
  enum.in_threads(13).send(method, &:check?)
@@ -184,8 +170,9 @@ describe 'in_threads' do
184
170
  end
185
171
 
186
172
  it 'should not yield all elements when not needed' do
187
- enum = CustomEnum.new do |&block|
188
- 100.times{ block[1] }
173
+ enum = []
174
+ def enum.each
175
+ 100.times{ yield 1 }
189
176
  fail
190
177
  end
191
178
 
@@ -195,9 +182,9 @@ describe 'in_threads' do
195
182
  end
196
183
 
197
184
  describe 'methods' do
198
- enumerable_methods = Enumerable.instance_methods
199
- in_threads_methods = 10.times.in_threads.class.instance_methods
200
- (enumerable_methods - in_threads_methods).each do |method|
185
+ missing_methods =
186
+ (Enumerable.instance_methods - InThreads.instance_methods).map(&:to_sym)
187
+ (missing_methods - InThreads::INCOMPATIBLE_METHODS).each do |method|
201
188
  pending method
202
189
  end
203
190
 
@@ -216,12 +203,12 @@ describe 'in_threads' do
216
203
  enum.in_threads.each(&:touch_n_value)
217
204
  end
218
205
 
219
- it 'should run faster with threads' do
206
+ it 'should run faster with threads', :retry => 3 do
220
207
  expect(measure{ enum.in_threads.each(&:value) }).
221
208
  to be < measure{ enum.each(&:value) } * speed_coef
222
209
  end
223
210
 
224
- it 'should run faster with more threads' do
211
+ it 'should run faster with more threads', :retry => 3 do
225
212
  expect(measure{ enum.in_threads(10).each(&:value) }).
226
213
  to be < measure{ enum.in_threads(2).each(&:value) } * speed_coef
227
214
  end
@@ -251,7 +238,7 @@ describe 'in_threads' do
251
238
  enum.in_threads.send(method){ |o, i| o.touch_n_value(i) }
252
239
  end
253
240
 
254
- it 'should run faster with threads' do
241
+ it 'should run faster with threads', :retry => 3 do
255
242
  expect(measure{ enum.in_threads.send(method, &runner) }).
256
243
  to be < measure{ enum.send(method, &runner) } * speed_coef
257
244
  end
@@ -288,7 +275,7 @@ describe 'in_threads' do
288
275
  end
289
276
  end
290
277
 
291
- it 'should run faster with threads' do
278
+ it 'should run faster with threads', :retry => 3 do
292
279
  expect(measure{ enum.in_threads.reverse_each(&:value) }).
293
280
  to be < measure{ enum.reverse_each(&:value) } * speed_coef
294
281
  end
@@ -334,7 +321,7 @@ describe 'in_threads' do
334
321
  expect(@a.length).to be <= enum.length * 0.5
335
322
  end
336
323
 
337
- it 'should run faster with threads' do
324
+ it 'should run faster with threads', :retry => 3 do
338
325
  boolean = %w[all? drop_while take_while].include?(method)
339
326
  enum = 30.times.map{ |i| ValueItem.new(i, boolean) }
340
327
  expect(measure{ enum.in_threads.send(method, &:check?) }).
@@ -361,7 +348,7 @@ describe 'in_threads' do
361
348
  enum.in_threads.send(method, &:touch_n_check?)
362
349
  end
363
350
 
364
- it 'should run faster with threads' do
351
+ it 'should run faster with threads', :retry => 3 do
365
352
  expect(measure{ enum.in_threads.send(method, &:check?) }).
366
353
  to be < measure{ enum.send(method, &:check?) } * speed_coef
367
354
  end
@@ -386,7 +373,7 @@ describe 'in_threads' do
386
373
  enum.in_threads.send(method, &:touch_n_value)
387
374
  end
388
375
 
389
- it 'should run faster with threads' do
376
+ it 'should run faster with threads', :retry => 3 do
390
377
  expect(measure{ enum.in_threads.send(method, &:value) }).
391
378
  to be < measure{ enum.send(method, &:value) } * speed_coef
392
379
  end
@@ -415,7 +402,7 @@ describe 'in_threads' do
415
402
  to eq(enum.send(method, 3, &runner))
416
403
  end
417
404
 
418
- it 'should run faster with threads' do
405
+ it 'should run faster with threads', :retry => 3 do
419
406
  expect(measure{ enum.in_threads.send(method, 3, &runner) }).
420
407
  to be < measure{ enum.send(method, 3, &runner) } * speed_coef
421
408
  end
@@ -451,7 +438,7 @@ describe 'in_threads' do
451
438
  to eq(enum.zip(enum, enum, &runner))
452
439
  end
453
440
 
454
- it 'should run faster with threads' do
441
+ it 'should run faster with threads', :retry => 3 do
455
442
  expect(measure{ enum.in_threads.zip(enum, enum, &runner) }).
456
443
  to be < measure{ enum.zip(enum, enum, &runner) } * speed_coef
457
444
  end
@@ -473,7 +460,7 @@ describe 'in_threads' do
473
460
  enum.in_threads.cycle(3, &:touch_n_value)
474
461
  end
475
462
 
476
- it 'should run faster with threads' do
463
+ it 'should run faster with threads', :retry => 3 do
477
464
  expect(measure{ enum.in_threads.cycle(3, &:value) }).
478
465
  to be < measure{ enum.cycle(3, &:value) } * speed_coef
479
466
  end
@@ -504,7 +491,7 @@ describe 'in_threads' do
504
491
  to eq(enum.grep(matcher, &:value))
505
492
  end
506
493
 
507
- it 'should run faster with threads' do
494
+ it 'should run faster with threads', :retry => 3 do
508
495
  expect(measure{ enum.in_threads.grep(matcher, &:value) }).
509
496
  to be < measure{ enum.grep(matcher, &:value) } * speed_coef
510
497
  end
@@ -522,10 +509,12 @@ describe 'in_threads' do
522
509
 
523
510
  describe_enum_method 'each_entry' do
524
511
  let(:enum) do
525
- CustomEnum.new do |&block|
526
- 10.times{ block[1] }
527
- 10.times{ block[2, 3] }
528
- 10.times{ block[4, 5, 6] }
512
+ [].tap do |enum|
513
+ def enum.each
514
+ 10.times{ yield 1 }
515
+ 10.times{ yield 2, 3 }
516
+ 10.times{ yield 4, 5, 6 }
517
+ end
529
518
  end
530
519
  end
531
520
  let(:runner){ proc{ |o| ValueItem.new(0, o).value } }
@@ -547,7 +536,7 @@ describe 'in_threads' do
547
536
  end
548
537
  end
549
538
 
550
- it 'should run faster with threads' do
539
+ it 'should run faster with threads', :retry => 3 do
551
540
  expect(measure{ enum.in_threads.each_entry(&runner) }).
552
541
  to be < measure{ enum.each_entry(&runner) } * speed_coef
553
542
  end
@@ -587,7 +576,7 @@ describe 'in_threads' do
587
576
  end
588
577
  end
589
578
 
590
- it 'should run faster with threads' do
579
+ it 'should run faster with threads', :retry => 3 do
591
580
  expect(measure{ enum.in_threads.send(method, &runner) }).
592
581
  to be < measure{ enum.send(method, &runner) } * speed_coef
593
582
  end
data/spec/spec_helper.rb CHANGED
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'rspec/retry'
3
+
4
+ RSpec.configure do |config|
5
+ config.verbose_retry = true # show retry status in spec process
6
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: in_threads
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kuchin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-31 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,20 +24,34 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-retry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.3'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rubocop
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ~>
32
46
  - !ruby/object:Gem::Version
33
- version: 0.26.0
47
+ version: '0.26'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ~>
39
53
  - !ruby/object:Gem::Version
40
- version: 0.26.0
54
+ version: '0.26'
41
55
  description:
42
56
  email:
43
57
  executables: []
@@ -64,20 +78,21 @@ require_paths:
64
78
  - lib
65
79
  required_ruby_version: !ruby/object:Gem::Requirement
66
80
  requirements:
67
- - - '>='
81
+ - - ! '>='
68
82
  - !ruby/object:Gem::Version
69
83
  version: '0'
70
84
  required_rubygems_version: !ruby/object:Gem::Requirement
71
85
  requirements:
72
- - - '>='
86
+ - - ! '>='
73
87
  - !ruby/object:Gem::Version
74
88
  version: '0'
75
89
  requirements: []
76
90
  rubyforge_project: in_threads
77
- rubygems_version: 2.4.2
91
+ rubygems_version: 2.4.5
78
92
  signing_key:
79
93
  specification_version: 4
80
94
  summary: Execute ruby code in parallel
81
95
  test_files:
82
96
  - spec/in_threads_spec.rb
83
97
  - spec/spec_helper.rb
98
+ has_rdoc: