agent 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- agent (1.0.0)
4
+ agent (0.9.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
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
@@ -10,5 +10,6 @@ module Agent
10
10
  class NotImplementedError < Exception; end
11
11
  class DefaultCaseAlreadyDefinedError < Exception; end
12
12
  class NegativeWaitGroupCount < Exception; end
13
+ class AlreadySelectedError < Exception; end
13
14
  end
14
15
  end
@@ -37,7 +37,7 @@ module Agent
37
37
  raise Errors::ChannelClosed if @closed
38
38
 
39
39
  if @blocking_once
40
- value, error = @blocking_once.perform do
40
+ _, error = @blocking_once.perform do
41
41
  @object = Marshal.load(yield)
42
42
  @received = true
43
43
  @cvar.signal
@@ -37,7 +37,7 @@ module Agent
37
37
  raise Errors::ChannelClosed if @closed
38
38
 
39
39
  if @blocking_once
40
- value, error = @blocking_once.perform do
40
+ _, error = @blocking_once.perform do
41
41
  yield @object
42
42
  @sent = true
43
43
  @cvar.signal
@@ -1,4 +1,3 @@
1
- require "agent/queue"
2
1
  require "agent/errors"
3
2
 
4
3
  module Agent
@@ -1,4 +1,3 @@
1
- require "agent/queue"
2
1
  require "agent/errors"
3
2
 
4
3
  module Agent
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Agent
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -48,7 +48,7 @@ describe Agent::Channel do
48
48
  # timeout blocking receive calls
49
49
  timed_out = false
50
50
  select! do |s|
51
- s.case(c, :receive){}
51
+ s.case(c, :receive)
52
52
  s.timeout(0.1){ timed_out = true }
53
53
  end
54
54
  timed_out.should == true
@@ -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
- }.should raise_error(Agent::Errors::BlockMissing)
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.cases.size.should == 0
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.cases.size.should == 0
252
+ s.default
237
253
  end
238
- }.should raise_error(Agent::Errors::BlockMissing)
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.cases.size.should == 0
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.0
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: 2012-03-28 00:00:00.000000000 Z
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: &2153154840 !ruby/object:Gem::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: *2153154840
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: &2153154240 !ruby/object:Gem::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: *2153154240
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.10
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