in_threads 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,10 +1,12 @@
1
1
  /pkg/
2
+ /*.gem
2
3
 
3
4
  /doc/
4
5
  /rdoc/
5
6
  /.yardoc/
6
7
  /coverage/
7
8
 
9
+ Gemfile.lock
8
10
  Makefile
9
11
  *.o
10
12
  *.bundle
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - jruby-18mode
8
+ - jruby-19mode
9
+ - rbx-18mode
10
+ - rbx-19mode
11
+ - ree
12
+ script: "bundle exec rspec"
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2011 Ivan Kuchin
1
+ Copyright (c) 2010-2013 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
@@ -32,4 +32,4 @@ You can use any Enumerable method, but some of them can not use threads (`inject
32
32
 
33
33
  ## Copyright
34
34
 
35
- Copyright (c) 2010-2011 Ivan Kuchin. See LICENSE.txt for details.
35
+ Copyright (c) 2010-2013 Ivan Kuchin. See LICENSE.txt for details.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'in_threads'
5
- s.version = '1.1.1'
5
+ s.version = '1.1.2'
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']
@@ -30,7 +30,7 @@ class InThreads
30
30
  instance_methods.map(&:to_s) -
31
31
  %w[__id__ __send__ class inspect instance_of? is_a? kind_of? nil? object_id respond_to? send]
32
32
  ).each{ |name| undef_method name }
33
- (private_instance_methods.map(&:to_s) - %w[initialize raise]).each{ |name| undef_method name }
33
+ (private_instance_methods.map(&:to_s) - %w[initialize raise method_missing]).each{ |name| undef_method name }
34
34
 
35
35
  attr_reader :enumerable, :thread_count
36
36
  def initialize(enumerable, thread_count = 10, &block)
@@ -92,7 +92,7 @@ class InThreads
92
92
  use :run_without_threads, :for => %w[
93
93
  inject reduce
94
94
  max min minmax sort
95
- entries to_a
95
+ entries to_a to_set
96
96
  drop take
97
97
  first
98
98
  include? member?
@@ -34,7 +34,6 @@ class InThreads
34
34
  @mutex = Mutex.new
35
35
  @filler = Thread.new do
36
36
  enum.each do |o|
37
- Thread.stop
38
37
  synchronize do
39
38
  @extractors.each do |extractor|
40
39
  extractor.push(o)
@@ -1,22 +1,23 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  class Item
4
- attr_reader :rand
5
4
  def initialize(i)
6
- @i = i
7
- @rand = Kernel.rand
8
- @sleep = Kernel.rand
5
+ @i, @value = i, Kernel.rand
9
6
  end
10
7
 
11
- class MiddleMatcher
8
+ def ==(other)
9
+ self.id == other.id
10
+ end
11
+
12
+ class HalfMatcher
12
13
  def ===(item)
13
14
  raise "#{item.inspect} is not an Item" unless item.is_a?(Item)
14
- (0.25..0.75) === item.rand
15
+ (0.25..0.75) === item.instance_variable_get(:@value)
15
16
  end
16
17
  end
17
18
 
18
19
  def value
19
- sleep; rand
20
+ sleep; @value
20
21
  end
21
22
 
22
23
  def check?
@@ -31,17 +32,22 @@ class Item
31
32
  touch(*args); check?
32
33
  end
33
34
 
35
+ protected
36
+
37
+ def id
38
+ [self.class, @i, @value]
39
+ end
40
+
34
41
  private
35
42
 
36
43
  def sleep
37
- Kernel.sleep @sleep * 0.01
44
+ Kernel.sleep 0.01
38
45
  end
39
46
  end
40
47
 
41
48
  class ValueItem < Item
42
49
  def initialize(i, value)
43
- super(i)
44
- @value = value
50
+ @i, @value = i, value
45
51
  end
46
52
 
47
53
  def value
@@ -59,7 +65,7 @@ def describe_enum_method(method, &block)
59
65
  describe(method, &block)
60
66
  else
61
67
  it "should not be defined" do
62
- exception_regexp = /^undefined method `#{Regexp.escape(method)}' for #<InThreads:0x[0-9a-f]+>$/
68
+ exception_regexp = /^undefined method `#{Regexp.escape(method)}' .*\bInThreads\b/
63
69
  proc{ enum.in_threads.send(method) }.should raise_error(NoMethodError, exception_regexp)
64
70
  end
65
71
  end
@@ -121,7 +127,7 @@ describe "in_threads" do
121
127
  @thread_count = 0
122
128
  @max_thread_count = 0
123
129
  @mutex = Mutex.new
124
- enum.in_threads(13).send(method) do |o|
130
+ enum.in_threads(4).send(method) do |o|
125
131
  @mutex.synchronize do
126
132
  @thread_count += 1
127
133
  @max_thread_count = [@max_thread_count, @thread_count].max
@@ -133,7 +139,7 @@ describe "in_threads" do
133
139
  res
134
140
  end
135
141
  @thread_count.should == 0
136
- @max_thread_count.should == 13
142
+ @max_thread_count.should == 4
137
143
  end
138
144
  end
139
145
  end
@@ -217,7 +223,7 @@ describe "in_threads" do
217
223
  end
218
224
 
219
225
  it "should fire same objects in reverse order" do
220
- @order = mock('order', :notify => nil)
226
+ @order = double('order', :notify => nil)
221
227
  @order.should_receive(:notify).with(enum.last).ordered
222
228
  @order.should_receive(:notify).with(enum[enum.length / 2]).ordered
223
229
  @order.should_receive(:notify).with(enum.first).ordered
@@ -366,7 +372,7 @@ describe "in_threads" do
366
372
  end
367
373
 
368
374
  describe "grep" do
369
- let(:matcher){ Item::MiddleMatcher.new }
375
+ let(:matcher){ Item::HalfMatcher.new }
370
376
 
371
377
  it "should fire same objects" do
372
378
  enum.each{ |o| o.should_receive(:touch).exactly(matcher === o ? 1 : 0).times }
@@ -392,7 +398,7 @@ describe "in_threads" do
392
398
  def each
393
399
  10.times{ yield 1 }
394
400
  10.times{ yield 2, 3 }
395
- 10.times{ yield }
401
+ 10.times{ yield 4, 5, 6 }
396
402
  end
397
403
  end
398
404
 
@@ -404,10 +410,10 @@ describe "in_threads" do
404
410
  end
405
411
 
406
412
  it "should execute block for each element" do
407
- @order = mock('order')
413
+ @order = double('order')
408
414
  @order.should_receive(:notify).with(1).exactly(10).times.ordered
409
415
  @order.should_receive(:notify).with([2, 3]).exactly(10).times.ordered
410
- @order.should_receive(:notify).with(nil).exactly(10).times.ordered
416
+ @order.should_receive(:notify).with([4, 5, 6]).exactly(10).times.ordered
411
417
  @mutex = Mutex.new
412
418
  enum.in_threads.each_entry do |o|
413
419
  @mutex.synchronize{ @order.notify(o) }
metadata CHANGED
@@ -1,46 +1,41 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: in_threads
3
- version: !ruby/object:Gem::Version
4
- hash: 17
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.2
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 1
9
- - 1
10
- version: 1.1.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Ivan Kuchin
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-12-13 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-08-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rspec
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :development
33
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
34
30
  description:
35
31
  email:
36
32
  executables: []
37
-
38
33
  extensions: []
39
-
40
34
  extra_rdoc_files: []
41
-
42
- files:
35
+ files:
43
36
  - .gitignore
37
+ - .travis.yml
38
+ - Gemfile
44
39
  - LICENSE.txt
45
40
  - README.markdown
46
41
  - in_threads.gemspec
@@ -50,39 +45,30 @@ files:
50
45
  - spec/in_threads_spec.rb
51
46
  - spec/spec_helper.rb
52
47
  homepage: http://github.com/toy/in_threads
53
- licenses:
48
+ licenses:
54
49
  - MIT
55
50
  post_install_message:
56
51
  rdoc_options: []
57
-
58
- require_paths:
52
+ require_paths:
59
53
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
54
+ required_ruby_version: !ruby/object:Gem::Requirement
61
55
  none: false
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- hash: 3
66
- segments:
67
- - 0
68
- version: "0"
69
- required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
61
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
78
66
  requirements: []
79
-
80
67
  rubyforge_project: in_threads
81
- rubygems_version: 1.8.12
68
+ rubygems_version: 1.8.23
82
69
  signing_key:
83
70
  specification_version: 3
84
71
  summary: Execute ruby code in parallel
85
- test_files:
72
+ test_files:
86
73
  - spec/in_threads_spec.rb
87
74
  - spec/spec_helper.rb
88
- has_rdoc: