threadlimiter 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +6 -0
- data/VERSION +1 -1
- data/lib/threadlimiter/threadlimiter.rb +9 -4
- data/lib/threadlimiter/version.rb +1 -1
- metadata +25 -41
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -18,7 +18,8 @@ class ThreadLimiter
|
|
18
18
|
|
19
19
|
# Initialize the ThreadLimiter.
|
20
20
|
# The optional parameter <i>limit</i> is the maximum number of concurrently running threads.
|
21
|
-
# Set <i>limit</i> to -1
|
21
|
+
# Set <i>limit</i> to -1 to fork threads without limiting the number of concurrently running threads.
|
22
|
+
# Set <i>limit</i> to 0 to join the newly created thread immediately, mimicking no-forking.
|
22
23
|
# Set options[:noblock] to true to start the new thread before waiting for resources.
|
23
24
|
|
24
25
|
def initialize(limit, options={})
|
@@ -37,10 +38,14 @@ class ThreadLimiter
|
|
37
38
|
# The list of arguments is passed to Thread.fork().
|
38
39
|
|
39
40
|
def fork(*args, &block)
|
40
|
-
if @limit
|
41
|
+
if @limit < 0
|
41
42
|
Thread.fork do
|
42
43
|
yield(*args)
|
43
44
|
end
|
45
|
+
elsif @limit == 0
|
46
|
+
Thread.fork do
|
47
|
+
yield(*args)
|
48
|
+
end.join # Because ThreadLimiter#fork() should return a new Thread.
|
44
49
|
else
|
45
50
|
cv_wait unless @noblock
|
46
51
|
|
@@ -113,10 +118,10 @@ class ThreadLimiter
|
|
113
118
|
def cv_signal
|
114
119
|
@mutex.synchronize do
|
115
120
|
@running -= 1
|
116
|
-
|
117
|
-
@cv.signal
|
118
121
|
end
|
119
122
|
|
123
|
+
@cv.signal
|
124
|
+
|
120
125
|
self
|
121
126
|
end
|
122
127
|
end
|
metadata
CHANGED
@@ -1,32 +1,23 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: threadlimiter
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Erik Veenstra
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2012-02-11 00:00:00 Z
|
12
|
+
date: 2012-03-17 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
|
-
|
14
|
+
description: Fork threads like Thread.fork, but limit the number of concurrently running
|
15
|
+
threads.
|
22
16
|
email: threadlimiter@erikveen.dds.nl
|
23
17
|
executables: []
|
24
|
-
|
25
18
|
extensions: []
|
26
|
-
|
27
19
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
files:
|
20
|
+
files:
|
30
21
|
- lib/threadlimiter.rb
|
31
22
|
- lib/threadlimiter/enumerable.rb
|
32
23
|
- lib/threadlimiter/threadlimiter.rb
|
@@ -38,43 +29,36 @@ files:
|
|
38
29
|
- test/test.rb
|
39
30
|
homepage: http://www.erikveen.dds.nl/threadlimiter/index.html
|
40
31
|
licenses: []
|
41
|
-
|
42
32
|
post_install_message:
|
43
|
-
rdoc_options:
|
33
|
+
rdoc_options:
|
44
34
|
- README
|
45
35
|
- LICENSE
|
46
36
|
- VERSION
|
47
37
|
- CHANGELOG
|
48
38
|
- --title
|
49
|
-
- threadlimiter (0.2.
|
39
|
+
- threadlimiter (0.2.1)
|
50
40
|
- --main
|
51
41
|
- README
|
52
|
-
require_paths:
|
42
|
+
require_paths:
|
53
43
|
- lib
|
54
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
45
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
60
|
-
|
61
|
-
- 0
|
62
|
-
version: "0"
|
63
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
51
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
segments:
|
70
|
-
- 0
|
71
|
-
version: "0"
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
72
56
|
requirements: []
|
73
|
-
|
74
57
|
rubyforge_project: threadlimiter
|
75
|
-
rubygems_version: 1.8.
|
58
|
+
rubygems_version: 1.8.18
|
76
59
|
signing_key:
|
77
60
|
specification_version: 3
|
78
|
-
summary: Fork threads like Thread.fork, but limit the number of concurrently running
|
79
|
-
|
61
|
+
summary: Fork threads like Thread.fork, but limit the number of concurrently running
|
62
|
+
threads.
|
63
|
+
test_files:
|
80
64
|
- test/test.rb
|