in_threads 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +9 -3
- data/VERSION +1 -1
- data/in_threads.gemspec +4 -4
- data/lib/in_threads.rb +1 -1
- data/spec/in_threads_spec.rb +14 -0
- metadata +17 -5
data/Rakefile
CHANGED
@@ -18,11 +18,17 @@ begin
|
|
18
18
|
task 'ghost' do
|
19
19
|
gem_path = Pathname(Gem.searcher.find(name).full_gem_path)
|
20
20
|
current_path = Pathname('.').expand_path
|
21
|
-
|
22
|
-
system(
|
23
|
-
system(*cmd + %W[ln -s #{current_path} #{gem_path}])
|
21
|
+
system('rm', '-r', gem_path)
|
22
|
+
system('ln', '-s', current_path, gem_path)
|
24
23
|
end
|
25
24
|
|
26
25
|
rescue LoadError
|
27
26
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
28
27
|
end
|
28
|
+
|
29
|
+
require 'spec/rake/spectask'
|
30
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
32
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/in_threads.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{in_threads}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Boba Fat"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-07-13}
|
13
13
|
s.extra_rdoc_files = [
|
14
14
|
"README.rdoc"
|
15
15
|
]
|
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.homepage = %q{http://github.com/toy/in_threads}
|
28
28
|
s.rdoc_options = ["--charset=UTF-8"]
|
29
29
|
s.require_paths = ["lib"]
|
30
|
-
s.rubygems_version = %q{1.3.
|
30
|
+
s.rubygems_version = %q{1.3.7}
|
31
31
|
s.summary = %q{Execute ruby blocks in parallel}
|
32
32
|
s.test_files = [
|
33
33
|
"spec/in_threads_spec.rb",
|
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
39
39
|
s.specification_version = 3
|
40
40
|
|
41
|
-
if Gem::Version.new(Gem::
|
41
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
42
|
else
|
43
43
|
end
|
44
44
|
else
|
data/lib/in_threads.rb
CHANGED
@@ -27,7 +27,7 @@ private
|
|
27
27
|
|
28
28
|
def run_in_threads(method, *args, &block)
|
29
29
|
@object.send(method, *args) do |*args|
|
30
|
-
|
30
|
+
while @threads.count(&:alive?) >= @max_threads
|
31
31
|
ThreadsWait.new(*@threads).next_wait
|
32
32
|
end
|
33
33
|
@threads << Thread.new(*args, &block)
|
data/spec/in_threads_spec.rb
CHANGED
@@ -19,6 +19,20 @@ describe InThreads do
|
|
19
19
|
@a.in_threads.each(&:hello)
|
20
20
|
end
|
21
21
|
|
22
|
+
it "should not run simulanteously more threads" do
|
23
|
+
@mutex = Mutex.new
|
24
|
+
@threads = 0
|
25
|
+
(1..100).to_a.in_threads(10).each do |i|
|
26
|
+
(0..10).include?(@threads).should be_true
|
27
|
+
@mutex.synchronize{ @threads += 1 }
|
28
|
+
(0..10).include?(@threads).should be_true
|
29
|
+
sleep 1 + rand * 1
|
30
|
+
(0..10).include?(@threads).should be_true
|
31
|
+
@mutex.synchronize{ @threads -= 1 }
|
32
|
+
(0..10).include?(@threads).should be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
22
36
|
it "should run faster than without threads" do
|
23
37
|
(measure{ @a.in_threads.each(&@sleepy_prock) } * 2).should be < measure{ @a.each(&@sleepy_prock) }
|
24
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: in_threads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Boba Fat
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-07-13 00:00:00 +04:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -41,21 +47,27 @@ rdoc_options:
|
|
41
47
|
require_paths:
|
42
48
|
- lib
|
43
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
44
51
|
requirements:
|
45
52
|
- - ">="
|
46
53
|
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
47
57
|
version: "0"
|
48
|
-
version:
|
49
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
50
60
|
requirements:
|
51
61
|
- - ">="
|
52
62
|
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
53
66
|
version: "0"
|
54
|
-
version:
|
55
67
|
requirements: []
|
56
68
|
|
57
69
|
rubyforge_project:
|
58
|
-
rubygems_version: 1.3.
|
70
|
+
rubygems_version: 1.3.7
|
59
71
|
signing_key:
|
60
72
|
specification_version: 3
|
61
73
|
summary: Execute ruby blocks in parallel
|