celluloid 0.12.2 → 0.12.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -146,9 +146,16 @@ module Celluloid
146
146
  end
147
147
 
148
148
  # Trap errors from actors we're linked to when they exit
149
- def trap_exit(callback)
150
- @exit_handler = callback.to_sym
149
+ def exit_handler(callback = nil)
150
+ if callback
151
+ @exit_handler = callback.to_sym
152
+ elsif defined?(@exit_handler)
153
+ @exit_handler
154
+ elsif superclass.respond_to? :exit_handler
155
+ superclass.exit_handler
156
+ end
151
157
  end
158
+ alias_method :trap_exit, :exit_handler
152
159
 
153
160
  # Configure a custom mailbox factory
154
161
  def use_mailbox(klass = nil, &block)
@@ -202,7 +209,7 @@ module Celluloid
202
209
  def actor_options
203
210
  {
204
211
  :mailbox => mailbox_factory,
205
- :exit_handler => @exit_handler,
212
+ :exit_handler => exit_handler,
206
213
  :exclusive_methods => @exclusive_methods,
207
214
  :task_class => task_class
208
215
  }
@@ -389,7 +389,7 @@ module Celluloid
389
389
 
390
390
  # Run a method inside a task unless it's exclusive
391
391
  def task(task_type, method_name = nil, &block)
392
- if @exclusives && (@exclusives == :all || @exclusives.include?(method_name))
392
+ if @exclusives && (@exclusives == :all || @exclusives.include?(method_name.to_sym))
393
393
  exclusive { block.call }
394
394
  else
395
395
  @task_class.new(task_type, &block).resume
@@ -1,4 +1,4 @@
1
1
  module Celluloid
2
- VERSION = '0.12.2'
2
+ VERSION = '0.12.3'
3
3
  def self.version; VERSION; end
4
4
  end
@@ -285,6 +285,24 @@ shared_context "a Celluloid Actor" do |included_module|
285
285
  @charlie = actor_class.new "Charlie Sheen"
286
286
  end
287
287
 
288
+ let(:supervisor_class) do
289
+ Class.new do # like a boss
290
+ include included_module
291
+ trap_exit :lambaste_subordinate
292
+
293
+ def initialize(name)
294
+ @name = name
295
+ @subordinate_lambasted = false
296
+ end
297
+
298
+ def subordinate_lambasted?; @subordinate_lambasted; end
299
+
300
+ def lambaste_subordinate(actor, reason)
301
+ @subordinate_lambasted = true
302
+ end
303
+ end
304
+ end
305
+
288
306
  it "links to other actors" do
289
307
  @kevin.link @charlie
290
308
  @kevin.monitoring?(@charlie).should be_true
@@ -323,23 +341,20 @@ shared_context "a Celluloid Actor" do |included_module|
323
341
  end
324
342
 
325
343
  it "traps exit messages from other actors" do
326
- boss = Class.new do # like a boss
327
- include included_module
328
- trap_exit :lambaste_subordinate
329
-
330
- def initialize(name)
331
- @name = name
332
- @subordinate_lambasted = false
333
- end
344
+ chuck = supervisor_class.new "Chuck Lorre"
345
+ chuck.link @charlie
334
346
 
335
- def subordinate_lambasted?; @subordinate_lambasted; end
347
+ expect do
348
+ @charlie.crash
349
+ end.to raise_exception(ExampleCrash)
336
350
 
337
- def lambaste_subordinate(actor, reason)
338
- @subordinate_lambasted = true
339
- end
340
- end
351
+ sleep 0.1 # hax to prevent a race between exit handling and the next call
352
+ chuck.should be_subordinate_lambasted
353
+ end
341
354
 
342
- chuck = boss.new "Chuck Lorre"
355
+ it "traps exit messages from other actors in subclasses" do
356
+ supervisor_subclass = Class.new(supervisor_class)
357
+ chuck = supervisor_subclass.new "Chuck Lorre"
343
358
  chuck.link @charlie
344
359
 
345
360
  expect do
@@ -418,7 +433,16 @@ shared_context "a Celluloid Actor" do |included_module|
418
433
  subject do
419
434
  Class.new do
420
435
  include included_module
421
- def exclusive_example
436
+
437
+ attr_reader :tasks
438
+
439
+ def initialize
440
+ @tasks = []
441
+ end
442
+
443
+ def exclusive_example(input = nil, sleep = false)
444
+ sleep Celluloid::TIMER_QUANTUM if sleep
445
+ @tasks << input
422
446
  exclusive?
423
447
  end
424
448
  exclusive :exclusive_example
@@ -436,6 +460,13 @@ shared_context "a Celluloid Actor" do |included_module|
436
460
  it "remains in exclusive mode inside nested blocks" do
437
461
  subject.nested_exclusive_example.should be_true
438
462
  end
463
+
464
+ it "executes the method in an exclusive order" do
465
+ subject.exclusive_example! :one, true
466
+ subject.exclusive_example! :two
467
+ sleep Celluloid::TIMER_QUANTUM * 2
468
+ subject.tasks.should == [:one, :two]
469
+ end
439
470
  end
440
471
 
441
472
  context "exclusive classes" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.12.3
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-10-10 00:00:00.000000000 Z
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: timers
16
- requirement: &70212079174880 !ruby/object:Gem::Requirement
16
+ requirement: &70118227807960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70212079174880
24
+ version_requirements: *70118227807960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: facter
27
- requirement: &70212079174420 !ruby/object:Gem::Requirement
27
+ requirement: &70118227807500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.6.12
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70212079174420
35
+ version_requirements: *70118227807500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70212079174040 !ruby/object:Gem::Requirement
38
+ requirement: &70118227807120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70212079174040
46
+ version_requirements: *70118227807120
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70212079189940 !ruby/object:Gem::Requirement
49
+ requirement: &70118227806660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70212079189940
57
+ version_requirements: *70118227806660
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: benchmark_suite
60
- requirement: &70212079189520 !ruby/object:Gem::Requirement
60
+ requirement: &70118227806240 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70212079189520
68
+ version_requirements: *70118227806240
69
69
  description: Celluloid enables people to build concurrent programs out of concurrent
70
70
  objects just as easily as they build sequential programs out of sequential objects
71
71
  email: