agent 0.9.0 → 0.9.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/Gemfile.lock +1 -1
- data/README.md +3 -3
- data/lib/agent/errors.rb +1 -0
- data/lib/agent/pop.rb +1 -1
- data/lib/agent/push.rb +1 -1
- data/lib/agent/queue/buffered.rb +0 -1
- data/lib/agent/queue/unbuffered.rb +0 -1
- data/lib/agent/selector.rb +11 -9
- data/lib/agent/version.rb +1 -1
- data/spec/channel_spec.rb +1 -1
- data/spec/selector_spec.rb +34 -18
- metadata +17 -7
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -36,7 +36,7 @@ A "select" statement chooses which of a set of possible communications will proc
|
|
36
36
|
cw = channel!(Integer, 1)
|
37
37
|
cr = channel!(Integer, 1)
|
38
38
|
|
39
|
-
select do |s|
|
39
|
+
select! do |s|
|
40
40
|
s.case(cr, :receive) { |value| do_something(value) }
|
41
41
|
s.case(cw, :send, 3)
|
42
42
|
end
|
@@ -47,7 +47,7 @@ In example above, cr is currently unavailable to read from (since its empty), bu
|
|
47
47
|
```ruby
|
48
48
|
cr = channel!(Integer, 1)
|
49
49
|
|
50
|
-
select do |s|
|
50
|
+
select! do |s|
|
51
51
|
s.case(cr, :receive) { |value| do_something(value) }
|
52
52
|
s.default { puts :default }
|
53
53
|
end
|
@@ -58,7 +58,7 @@ In this example, cr is unavailable for read (since its empty), but we also provi
|
|
58
58
|
```ruby
|
59
59
|
cr = channel!(Integer, 1)
|
60
60
|
|
61
|
-
select do |s|
|
61
|
+
select! do |s|
|
62
62
|
s.case(cr, :receive) { |value| do_something(value) }
|
63
63
|
s.timeout(1.0) { puts :timeout }
|
64
64
|
end
|
data/lib/agent/errors.rb
CHANGED
data/lib/agent/pop.rb
CHANGED
data/lib/agent/push.rb
CHANGED
data/lib/agent/queue/buffered.rb
CHANGED
data/lib/agent/selector.rb
CHANGED
@@ -11,11 +11,6 @@ module Agent
|
|
11
11
|
selector = Selector.new
|
12
12
|
yield selector
|
13
13
|
selector.select
|
14
|
-
ensure
|
15
|
-
if selector
|
16
|
-
selector.close_default_channel
|
17
|
-
selector.dequeue_operations
|
18
|
-
end
|
19
14
|
end
|
20
15
|
|
21
16
|
class Selector
|
@@ -29,6 +24,8 @@ module Agent
|
|
29
24
|
@operations = {}
|
30
25
|
@blocking_once = BlockingOnce.new
|
31
26
|
@notifier = Notifier.new
|
27
|
+
@default_case = nil
|
28
|
+
@selected = false
|
32
29
|
end
|
33
30
|
|
34
31
|
def default(&blk)
|
@@ -47,12 +44,13 @@ module Agent
|
|
47
44
|
|
48
45
|
def case(chan, direction, value=nil, &blk)
|
49
46
|
raise "invalid case, must be a channel" unless chan.is_a?(Channel)
|
50
|
-
raise Errors::BlockMissing if blk.nil? && direction == :receive
|
51
47
|
raise Errors::InvalidDirection if direction != :send && direction != :receive
|
52
48
|
add_case(chan, direction, value, &blk)
|
53
49
|
end
|
54
50
|
|
55
51
|
def select
|
52
|
+
raise Errors::AlreadySelectedError if @selected
|
53
|
+
|
56
54
|
if !@ordered_cases.empty?
|
57
55
|
@ordered_cases.each do |cse|
|
58
56
|
if cse.direction == :send
|
@@ -76,8 +74,15 @@ module Agent
|
|
76
74
|
|
77
75
|
execute_case(@notifier.payload)
|
78
76
|
end
|
77
|
+
ensure
|
78
|
+
@selected = true
|
79
|
+
close_default_channel
|
80
|
+
dequeue_operations
|
79
81
|
end
|
80
82
|
|
83
|
+
|
84
|
+
protected
|
85
|
+
|
81
86
|
def dequeue_operations
|
82
87
|
@operations.each do |channel, operations|
|
83
88
|
channel.remove_operations(operations)
|
@@ -88,9 +93,6 @@ module Agent
|
|
88
93
|
@default_case.channel.close if @default_case
|
89
94
|
end
|
90
95
|
|
91
|
-
|
92
|
-
protected
|
93
|
-
|
94
96
|
def add_case(chan, direction, value=nil, &blk)
|
95
97
|
uuid = UUID.generate
|
96
98
|
cse = Case.new(uuid, chan, direction, value, blk)
|
data/lib/agent/version.rb
CHANGED
data/spec/channel_spec.rb
CHANGED
data/spec/selector_spec.rb
CHANGED
@@ -27,6 +27,23 @@ describe Agent::Selector do
|
|
27
27
|
(Time.now.to_f - now).should be_within(0.05).of(0.1)
|
28
28
|
end
|
29
29
|
|
30
|
+
it "should not raise an error when a block is missing on default" do
|
31
|
+
lambda {
|
32
|
+
select! do |s|
|
33
|
+
s.default
|
34
|
+
end
|
35
|
+
}.should_not raise_error(Agent::Errors::BlockMissing)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not raise an error when a block is missing on timeout" do
|
39
|
+
lambda {
|
40
|
+
select! do |s|
|
41
|
+
s.timeout(1)
|
42
|
+
s.default
|
43
|
+
end
|
44
|
+
}.should_not raise_error(Agent::Errors::BlockMissing)
|
45
|
+
end
|
46
|
+
|
30
47
|
context "with unbuffered channels" do
|
31
48
|
before do
|
32
49
|
@c = channel!(Integer)
|
@@ -38,28 +55,27 @@ describe Agent::Selector do
|
|
38
55
|
|
39
56
|
it "should evaluate select statements top to bottom" do
|
40
57
|
select! do |s|
|
41
|
-
s.case(@c, :send, 1)
|
42
|
-
s.case(@c, :receive)
|
43
|
-
s.default
|
58
|
+
s.case(@c, :send, 1)
|
59
|
+
s.case(@c, :receive)
|
60
|
+
s.default
|
44
61
|
s.cases.size.should == 3
|
45
62
|
end
|
46
63
|
end
|
47
64
|
|
48
|
-
it "should raise an error when a block is missing on receive" do
|
65
|
+
it "should not raise an error when a block is missing on receive" do
|
49
66
|
lambda {
|
50
67
|
select! do |s|
|
51
68
|
s.case(@c, :receive)
|
69
|
+
s.default
|
52
70
|
end
|
53
|
-
}.
|
71
|
+
}.should_not raise_error(Agent::Errors::BlockMissing)
|
54
72
|
end
|
55
73
|
|
56
74
|
it "should not raise an error when a block is missing on send" do
|
57
75
|
lambda {
|
58
|
-
go!{ @c.receive }
|
59
|
-
|
60
76
|
select! do |s|
|
61
77
|
s.case(@c, :send, 1)
|
62
|
-
s.
|
78
|
+
s.default
|
63
79
|
end
|
64
80
|
}.should_not raise_error(Agent::Errors::BlockMissing)
|
65
81
|
end
|
@@ -98,7 +114,7 @@ describe Agent::Selector do
|
|
98
114
|
lambda {
|
99
115
|
select! do |s|
|
100
116
|
s.case(@c, :send, 1)
|
101
|
-
s.case(@c, :receive)
|
117
|
+
s.case(@c, :receive)
|
102
118
|
end
|
103
119
|
}.should raise_error(Agent::Errors::ChannelClosed)
|
104
120
|
end
|
@@ -168,7 +184,7 @@ describe Agent::Selector do
|
|
168
184
|
go!{sleep(0.2); c.receive[0].should == 2 }
|
169
185
|
|
170
186
|
select! do |s|
|
171
|
-
s.case(c, :send, 2)
|
187
|
+
s.case(c, :send, 2)
|
172
188
|
end
|
173
189
|
|
174
190
|
(Time.now.to_f - now).should be_within(0.1).of(0.2)
|
@@ -223,26 +239,26 @@ describe Agent::Selector do
|
|
223
239
|
|
224
240
|
it "should evaluate select statements top to bottom" do
|
225
241
|
select! do |s|
|
226
|
-
s.case(@c, :send, 1)
|
227
|
-
s.case(@c, :receive)
|
242
|
+
s.case(@c, :send, 1)
|
243
|
+
s.case(@c, :receive)
|
228
244
|
s.cases.size.should == 2
|
229
245
|
end
|
230
246
|
end
|
231
247
|
|
232
|
-
it "should raise an error when a block is missing on receive" do
|
248
|
+
it "should not raise an error when a block is missing on receive" do
|
233
249
|
lambda {
|
234
250
|
select! do |s|
|
235
251
|
s.case(@c, :receive)
|
236
|
-
s.
|
252
|
+
s.default
|
237
253
|
end
|
238
|
-
}.
|
254
|
+
}.should_not raise_error(Agent::Errors::BlockMissing)
|
239
255
|
end
|
240
256
|
|
241
257
|
it "should not raise an error when a block is missing on send" do
|
242
258
|
lambda {
|
243
259
|
select! do |s|
|
244
260
|
s.case(@c, :send, 1)
|
245
|
-
s.
|
261
|
+
s.default
|
246
262
|
end
|
247
263
|
}.should_not raise_error(Agent::Errors::BlockMissing)
|
248
264
|
end
|
@@ -283,7 +299,7 @@ describe Agent::Selector do
|
|
283
299
|
lambda {
|
284
300
|
select! do |s|
|
285
301
|
s.case(@c, :send, 1)
|
286
|
-
s.case(@c, :send, 2)
|
302
|
+
s.case(@c, :send, 2)
|
287
303
|
end
|
288
304
|
}.should raise_error(Agent::Errors::ChannelClosed)
|
289
305
|
end
|
@@ -348,7 +364,7 @@ describe Agent::Selector do
|
|
348
364
|
go!{sleep(0.2); c.receive }
|
349
365
|
|
350
366
|
select! do |s|
|
351
|
-
s.case(c, :send, 2)
|
367
|
+
s.case(c, :send, 2)
|
352
368
|
end
|
353
369
|
|
354
370
|
c.receive[0].should == 2
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rspec
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
description: Agent is a diverse family of related approaches for modelling concurrent
|
37
47
|
systems, in Ruby
|
38
48
|
email:
|
@@ -114,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
124
|
version: '0'
|
115
125
|
requirements: []
|
116
126
|
rubyforge_project: agent
|
117
|
-
rubygems_version: 1.8.
|
127
|
+
rubygems_version: 1.8.24
|
118
128
|
signing_key:
|
119
129
|
specification_version: 3
|
120
130
|
summary: Agent is a diverse family of related approaches for modelling concurrent
|