celluloid 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -8
- data/lib/celluloid.rb +16 -7
- data/lib/celluloid.rbc +702 -0
- data/lib/celluloid/actor.rb +98 -32
- data/lib/celluloid/actor.rbc +4637 -0
- data/lib/celluloid/actor_proxy.rb +19 -3
- data/lib/celluloid/actor_proxy.rbc +1884 -0
- data/lib/celluloid/calls.rbc +1384 -0
- data/lib/celluloid/core_ext.rb +1 -1
- data/lib/celluloid/core_ext.rbc +255 -0
- data/lib/celluloid/events.rb +1 -1
- data/lib/celluloid/events.rbc +357 -0
- data/lib/celluloid/future.rbc +747 -0
- data/lib/celluloid/linking.rb +10 -0
- data/lib/celluloid/linking.rbc +1837 -0
- data/lib/celluloid/mailbox.rb +31 -37
- data/lib/celluloid/mailbox.rbc +1843 -0
- data/lib/celluloid/reference.rbc +128 -0
- data/lib/celluloid/registry.rbc +784 -0
- data/lib/celluloid/responses.rbc +344 -0
- data/lib/celluloid/supervisor.rbc +1032 -0
- data/lib/celluloid/tuple.rbc +459 -0
- data/lib/celluloid/version.rb +4 -0
- data/lib/celluloid/version.rbc +198 -0
- data/lib/celluloid/waker.rbc +0 -0
- metadata +36 -57
- data/.autotest +0 -14
- data/.document +0 -5
- data/.rspec +0 -3
- data/CHANGES.md +0 -8
- data/Gemfile +0 -13
- data/Gemfile.lock +0 -27
- data/LICENSE.txt +0 -20
- data/Rakefile +0 -51
- data/VERSION +0 -1
- data/celluloid.gemspec +0 -85
- data/lib/celluloid/waker.rb +0 -41
- data/spec/actor_spec.rb +0 -141
- data/spec/future_spec.rb +0 -20
- data/spec/mailbox_spec.rb +0 -50
- data/spec/registry_spec.rb +0 -22
- data/spec/spec_helper.rb +0 -9
- data/spec/supervisor_spec.rb +0 -94
- data/spec/waker_spec.rb +0 -34
data/Rakefile
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'rake'
|
11
|
-
|
12
|
-
require 'jeweler'
|
13
|
-
Jeweler::Tasks.new do |gem|
|
14
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
-
gem.name = "celluloid"
|
16
|
-
gem.homepage = "http://github.com/tarcieri/celluloid"
|
17
|
-
gem.license = "MIT"
|
18
|
-
gem.summary = "Ruby concurrency made easy! Or at least, easier..."
|
19
|
-
gem.description = "Celluloid is a concurrent object framework inspired by the Actor Model"
|
20
|
-
gem.email = "tony@medioh.com"
|
21
|
-
gem.authors = ["Tony Arcieri"]
|
22
|
-
|
23
|
-
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
24
|
-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
25
|
-
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
26
|
-
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
27
|
-
end
|
28
|
-
Jeweler::RubygemsDotOrgTasks.new
|
29
|
-
|
30
|
-
require 'rspec/core'
|
31
|
-
require 'rspec/core/rake_task'
|
32
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
33
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
34
|
-
end
|
35
|
-
|
36
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
37
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
38
|
-
spec.rcov = true
|
39
|
-
end
|
40
|
-
|
41
|
-
task :default => :spec
|
42
|
-
|
43
|
-
require 'rake/rdoctask'
|
44
|
-
Rake::RDocTask.new do |rdoc|
|
45
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
-
|
47
|
-
rdoc.rdoc_dir = 'rdoc'
|
48
|
-
rdoc.title = "celluloid #{version}"
|
49
|
-
rdoc.rdoc_files.include('README*')
|
50
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.3
|
data/celluloid.gemspec
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{celluloid}
|
8
|
-
s.version = "0.0.3"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Tony Arcieri"]
|
12
|
-
s.date = %q{2011-05-11}
|
13
|
-
s.description = %q{Celluloid is a concurrent object framework inspired by the Actor Model}
|
14
|
-
s.email = %q{tony@medioh.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.md"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".autotest",
|
21
|
-
".document",
|
22
|
-
".rspec",
|
23
|
-
"CHANGES.md",
|
24
|
-
"Gemfile",
|
25
|
-
"Gemfile.lock",
|
26
|
-
"LICENSE.txt",
|
27
|
-
"README.md",
|
28
|
-
"Rakefile",
|
29
|
-
"VERSION",
|
30
|
-
"celluloid.gemspec",
|
31
|
-
"lib/celluloid.rb",
|
32
|
-
"lib/celluloid/actor.rb",
|
33
|
-
"lib/celluloid/actor_proxy.rb",
|
34
|
-
"lib/celluloid/calls.rb",
|
35
|
-
"lib/celluloid/core_ext.rb",
|
36
|
-
"lib/celluloid/events.rb",
|
37
|
-
"lib/celluloid/future.rb",
|
38
|
-
"lib/celluloid/linking.rb",
|
39
|
-
"lib/celluloid/mailbox.rb",
|
40
|
-
"lib/celluloid/registry.rb",
|
41
|
-
"lib/celluloid/responses.rb",
|
42
|
-
"lib/celluloid/supervisor.rb",
|
43
|
-
"lib/celluloid/waker.rb",
|
44
|
-
"spec/actor_spec.rb",
|
45
|
-
"spec/future_spec.rb",
|
46
|
-
"spec/mailbox_spec.rb",
|
47
|
-
"spec/registry_spec.rb",
|
48
|
-
"spec/spec_helper.rb",
|
49
|
-
"spec/supervisor_spec.rb",
|
50
|
-
"spec/waker_spec.rb"
|
51
|
-
]
|
52
|
-
s.homepage = %q{http://github.com/tarcieri/celluloid}
|
53
|
-
s.licenses = ["MIT"]
|
54
|
-
s.require_paths = ["lib"]
|
55
|
-
s.rubygems_version = %q{1.6.2}
|
56
|
-
s.summary = %q{Ruby concurrency made easy! Or at least, easier...}
|
57
|
-
s.test_files = [
|
58
|
-
"spec/actor_spec.rb",
|
59
|
-
"spec/future_spec.rb",
|
60
|
-
"spec/mailbox_spec.rb",
|
61
|
-
"spec/registry_spec.rb",
|
62
|
-
"spec/spec_helper.rb",
|
63
|
-
"spec/supervisor_spec.rb",
|
64
|
-
"spec/waker_spec.rb"
|
65
|
-
]
|
66
|
-
|
67
|
-
if s.respond_to? :specification_version then
|
68
|
-
s.specification_version = 3
|
69
|
-
|
70
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
71
|
-
s.add_development_dependency(%q<rspec>, [">= 2.3.0"])
|
72
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
73
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
74
|
-
else
|
75
|
-
s.add_dependency(%q<rspec>, [">= 2.3.0"])
|
76
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
77
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
78
|
-
end
|
79
|
-
else
|
80
|
-
s.add_dependency(%q<rspec>, [">= 2.3.0"])
|
81
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
82
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
data/lib/celluloid/waker.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module Celluloid
|
2
|
-
class WakerError < StandardError; end # You can't wake the dead
|
3
|
-
|
4
|
-
# Wakes up sleepy threads so that they can check their mailbox
|
5
|
-
# Works like a ConditionVariable, except it's implemented as an IO object so
|
6
|
-
# that it can be multiplexed alongside other IO objects.
|
7
|
-
class Waker
|
8
|
-
PAYLOAD = "\0" # the payload doesn't matter. each byte is a signal
|
9
|
-
def initialize
|
10
|
-
@receiver, @sender = IO.pipe
|
11
|
-
end
|
12
|
-
|
13
|
-
# Wakes up the thread that is waiting for this Waker
|
14
|
-
def signal
|
15
|
-
@sender << PAYLOAD
|
16
|
-
nil
|
17
|
-
rescue IOError, Errno::EPIPE, Errno::EBADF
|
18
|
-
raise WakerError, "waker is already dead"
|
19
|
-
end
|
20
|
-
|
21
|
-
# Wait for another thread to signal this Waker
|
22
|
-
def wait
|
23
|
-
byte = @receiver.read(1)
|
24
|
-
raise WakerError, "can't wait on a dead waker" unless byte == PAYLOAD
|
25
|
-
rescue IOError
|
26
|
-
raise WakerError, "can't wait on a dead waker"
|
27
|
-
end
|
28
|
-
|
29
|
-
# Return the IO object which will be readable when this Waker is signaled
|
30
|
-
def io
|
31
|
-
@receiver
|
32
|
-
end
|
33
|
-
|
34
|
-
# Clean up the IO objects associated with this waker
|
35
|
-
def cleanup
|
36
|
-
@receiver.close rescue nil
|
37
|
-
@sender.close rescue nil
|
38
|
-
nil
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/spec/actor_spec.rb
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Celluloid::Actor do
|
4
|
-
before do
|
5
|
-
class MyActor
|
6
|
-
include Celluloid::Actor
|
7
|
-
attr_reader :name
|
8
|
-
|
9
|
-
def initialize(name)
|
10
|
-
@name = name
|
11
|
-
end
|
12
|
-
|
13
|
-
def change_name(new_name)
|
14
|
-
@name = new_name
|
15
|
-
end
|
16
|
-
|
17
|
-
def greet
|
18
|
-
"Hi, I'm #{@name}"
|
19
|
-
end
|
20
|
-
|
21
|
-
class Crash < StandardError; end
|
22
|
-
def crash
|
23
|
-
raise Crash, "the spec purposely crashed me :("
|
24
|
-
end
|
25
|
-
|
26
|
-
def crash_with_abort(reason)
|
27
|
-
abort Crash.new(reason)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it "handles synchronous calls" do
|
33
|
-
actor = MyActor.spawn "Troy McClure"
|
34
|
-
actor.greet.should == "Hi, I'm Troy McClure"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "raises NoMethodError when a nonexistent method is called" do
|
38
|
-
actor = MyActor.spawn "Billy Bob Thornton"
|
39
|
-
|
40
|
-
proc do
|
41
|
-
actor.the_method_that_wasnt_there
|
42
|
-
end.should raise_exception(NoMethodError)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "reraises exceptions which occur during synchronous calls in the caller" do
|
46
|
-
actor = MyActor.spawn "James Dean" # is this in bad taste?
|
47
|
-
|
48
|
-
proc do
|
49
|
-
actor.crash
|
50
|
-
end.should raise_exception(MyActor::Crash)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "raises exceptions in the caller when abort is called, but keeps running" do
|
54
|
-
actor = MyActor.spawn "Al Pacino"
|
55
|
-
|
56
|
-
proc do
|
57
|
-
actor.crash_with_abort MyActor::Crash.new("You die motherfucker!")
|
58
|
-
end.should raise_exception(MyActor::Crash)
|
59
|
-
|
60
|
-
actor.should be_alive
|
61
|
-
end
|
62
|
-
|
63
|
-
it "raises DeadActorError if methods are synchronously called on a dead actor" do
|
64
|
-
actor = MyActor.spawn "James Dean"
|
65
|
-
actor.crash rescue nil
|
66
|
-
|
67
|
-
proc do
|
68
|
-
actor.greet
|
69
|
-
end.should raise_exception(Celluloid::DeadActorError)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "handles asynchronous calls" do
|
73
|
-
actor = MyActor.spawn "Troy McClure"
|
74
|
-
actor.change_name! "Charlie Sheen"
|
75
|
-
actor.greet.should == "Hi, I'm Charlie Sheen"
|
76
|
-
end
|
77
|
-
|
78
|
-
it "knows when it's running as an actor" do
|
79
|
-
obj = MyActor.new "I'm an object"
|
80
|
-
obj.actor?.should be_false
|
81
|
-
|
82
|
-
actor = MyActor.spawn "Troy McClure"
|
83
|
-
actor.actor?.should be_true
|
84
|
-
end
|
85
|
-
|
86
|
-
it "inspects properly" do
|
87
|
-
actor = MyActor.spawn "Troy McClure"
|
88
|
-
actor.inspect.should match(/Celluloid::Actor\(MyActor/)
|
89
|
-
actor.inspect.should include('@name="Troy McClure"')
|
90
|
-
actor.inspect.should_not include("@celluloid")
|
91
|
-
end
|
92
|
-
|
93
|
-
context :linking do
|
94
|
-
before :each do
|
95
|
-
@kevin = MyActor.spawn "Kevin Bacon" # Some six degrees action here
|
96
|
-
@charlie = MyActor.spawn "Charlie Sheen"
|
97
|
-
end
|
98
|
-
|
99
|
-
it "links to other actors" do
|
100
|
-
@kevin.link @charlie
|
101
|
-
@kevin.linked_to?(@charlie).should be_true
|
102
|
-
@charlie.linked_to?(@kevin).should be_true
|
103
|
-
end
|
104
|
-
|
105
|
-
it "unlinks from other actors" do
|
106
|
-
@kevin.link @charlie
|
107
|
-
@kevin.unlink @charlie
|
108
|
-
|
109
|
-
@kevin.linked_to?(@charlie).should be_false
|
110
|
-
@charlie.linked_to?(@kevin).should be_false
|
111
|
-
end
|
112
|
-
|
113
|
-
it "traps exit messages from other actors" do
|
114
|
-
class Boss # like a boss
|
115
|
-
include Celluloid::Actor
|
116
|
-
trap_exit :lambaste_subordinate
|
117
|
-
|
118
|
-
def initialize(name)
|
119
|
-
@name = name
|
120
|
-
@subordinate_lambasted = false
|
121
|
-
end
|
122
|
-
|
123
|
-
def subordinate_lambasted?; @subordinate_lambasted; end
|
124
|
-
|
125
|
-
def lambaste_subordinate(actor, reason)
|
126
|
-
@subordinate_lambasted = true
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
chuck = Boss.spawn "Chuck Lorre"
|
131
|
-
chuck.link @charlie
|
132
|
-
|
133
|
-
proc do
|
134
|
-
@charlie.crash
|
135
|
-
end.should raise_exception(MyActor::Crash)
|
136
|
-
|
137
|
-
sleep 0.1 # hax to prevent a race between exit handling and the next call
|
138
|
-
chuck.should be_subordinate_lambasted
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
data/spec/future_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Celluloid::Future do
|
4
|
-
it "creates future objects that can be retrieved later" do
|
5
|
-
future = Celluloid::Future() { 40 + 2 }
|
6
|
-
future.value.should == 42
|
7
|
-
end
|
8
|
-
|
9
|
-
it "passes arguments to future blocks" do
|
10
|
-
future = Celluloid::Future(40) { |n| n + 2 }
|
11
|
-
future.value.should == 42
|
12
|
-
end
|
13
|
-
|
14
|
-
it "reraises exceptions that occur when the value is retrieved" do
|
15
|
-
class ExampleError < StandardError; end
|
16
|
-
|
17
|
-
future = Celluloid::Future() { raise ExampleError, "oh noes crash!" }
|
18
|
-
proc { future.value }.should raise_exception(ExampleError)
|
19
|
-
end
|
20
|
-
end
|
data/spec/mailbox_spec.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class TestEvent < Celluloid::SystemEvent; end
|
4
|
-
|
5
|
-
describe Celluloid::Mailbox do
|
6
|
-
before :each do
|
7
|
-
@mailbox = Celluloid::Mailbox.new
|
8
|
-
end
|
9
|
-
|
10
|
-
it "receives messages" do
|
11
|
-
message = :ohai
|
12
|
-
|
13
|
-
@mailbox << message
|
14
|
-
@mailbox.receive.should == message
|
15
|
-
end
|
16
|
-
|
17
|
-
it "raises system events when received" do
|
18
|
-
@mailbox.system_event TestEvent.new("example")
|
19
|
-
|
20
|
-
proc do
|
21
|
-
@mailbox.receive
|
22
|
-
end.should raise_exception(TestEvent)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "prioritizes system events over other messages" do
|
26
|
-
@mailbox << :dummy1
|
27
|
-
@mailbox << :dummy2
|
28
|
-
@mailbox.system_event TestEvent.new("example")
|
29
|
-
|
30
|
-
proc do
|
31
|
-
@mailbox.receive
|
32
|
-
end.should raise_exception(TestEvent)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "selectively receives messages with a block" do
|
36
|
-
class Foo; end
|
37
|
-
class Bar; end
|
38
|
-
class Baz; end
|
39
|
-
|
40
|
-
foo, bar, baz = Foo.new, Bar.new, Baz.new
|
41
|
-
|
42
|
-
@mailbox << baz
|
43
|
-
@mailbox << foo
|
44
|
-
@mailbox << bar
|
45
|
-
|
46
|
-
@mailbox.receive { |msg| msg.is_a? Foo }.should == foo
|
47
|
-
@mailbox.receive { |msg| msg.is_a? Bar }.should == bar
|
48
|
-
@mailbox.receive.should == baz
|
49
|
-
end
|
50
|
-
end
|
data/spec/registry_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Celluloid::Registry do
|
4
|
-
class Marilyn
|
5
|
-
include Celluloid::Actor
|
6
|
-
|
7
|
-
def sing_for(person)
|
8
|
-
"o/~ Happy birthday, #{person}"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it "registers Actors" do
|
13
|
-
Celluloid::Actor[:marilyn] = Marilyn.spawn
|
14
|
-
Celluloid::Actor[:marilyn].sing_for("Mr. President").should == "o/~ Happy birthday, Mr. President"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "refuses to register non-Actors" do
|
18
|
-
proc do
|
19
|
-
Celluloid::Actor[:impostor] = Object.new
|
20
|
-
end.should raise_error(ArgumentError)
|
21
|
-
end
|
22
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
-
$LOAD_PATH.unshift File.dirname(__FILE__)
|
3
|
-
|
4
|
-
require 'rspec'
|
5
|
-
require 'celluloid'
|
6
|
-
|
7
|
-
# Requires supporting files with custom matchers and macros, etc,
|
8
|
-
# in ./support/ and its subdirectories.
|
9
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
data/spec/supervisor_spec.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Celluloid::Supervisor do
|
4
|
-
before do
|
5
|
-
class SubordinateDead < StandardError; end
|
6
|
-
|
7
|
-
class Subordinate
|
8
|
-
include Celluloid::Actor
|
9
|
-
attr_reader :state
|
10
|
-
|
11
|
-
def initialize(state)
|
12
|
-
@state = state
|
13
|
-
end
|
14
|
-
|
15
|
-
def crack_the_whip
|
16
|
-
case @state
|
17
|
-
when :idle
|
18
|
-
@state = :working
|
19
|
-
else raise SubordinateDead, "the spec purposely crashed me :("
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it "restarts actors when they die" do
|
26
|
-
supervisor = Celluloid::Supervisor.supervise(Subordinate, :idle)
|
27
|
-
subordinate = supervisor.actor
|
28
|
-
subordinate.state.should == :idle
|
29
|
-
|
30
|
-
subordinate.crack_the_whip
|
31
|
-
subordinate.state.should == :working
|
32
|
-
|
33
|
-
proc do
|
34
|
-
subordinate.crack_the_whip
|
35
|
-
end.should raise_exception(SubordinateDead)
|
36
|
-
sleep 0.1 # hax to prevent race :(
|
37
|
-
subordinate.should_not be_alive
|
38
|
-
|
39
|
-
new_subordinate = supervisor.actor
|
40
|
-
new_subordinate.should_not == subordinate
|
41
|
-
new_subordinate.state.should == :idle
|
42
|
-
end
|
43
|
-
|
44
|
-
it "registers actors and reregisters them when they die" do
|
45
|
-
supervisor = Celluloid::Supervisor.supervise_as(:subordinate, Subordinate, :idle)
|
46
|
-
subordinate = Celluloid::Actor[:subordinate]
|
47
|
-
subordinate.state.should == :idle
|
48
|
-
|
49
|
-
subordinate.crack_the_whip
|
50
|
-
subordinate.state.should == :working
|
51
|
-
|
52
|
-
proc do
|
53
|
-
subordinate.crack_the_whip
|
54
|
-
end.should raise_exception(SubordinateDead)
|
55
|
-
sleep 0.1 # hax to prevent race :(
|
56
|
-
subordinate.should_not be_alive
|
57
|
-
|
58
|
-
new_subordinate = Celluloid::Actor[:subordinate]
|
59
|
-
new_subordinate.should_not == subordinate
|
60
|
-
new_subordinate.state.should == :idle
|
61
|
-
end
|
62
|
-
|
63
|
-
it "creates supervisors via Actor.supervise" do
|
64
|
-
supervisor = Subordinate.supervise(:working)
|
65
|
-
subordinate = supervisor.actor
|
66
|
-
subordinate.state.should == :working
|
67
|
-
|
68
|
-
proc do
|
69
|
-
subordinate.crack_the_whip
|
70
|
-
end.should raise_exception(SubordinateDead)
|
71
|
-
sleep 0.1 # hax to prevent race :(
|
72
|
-
subordinate.should_not be_alive
|
73
|
-
|
74
|
-
new_subordinate = supervisor.actor
|
75
|
-
new_subordinate.should_not == subordinate
|
76
|
-
new_subordinate.state.should == :working
|
77
|
-
end
|
78
|
-
|
79
|
-
it "creates supervisors and registers actors via Actor.supervise_as" do
|
80
|
-
supervisor = Subordinate.supervise_as(:subordinate, :working)
|
81
|
-
subordinate = Celluloid::Actor[:subordinate]
|
82
|
-
subordinate.state.should == :working
|
83
|
-
|
84
|
-
proc do
|
85
|
-
subordinate.crack_the_whip
|
86
|
-
end.should raise_exception(SubordinateDead)
|
87
|
-
sleep 0.1 # hax to prevent race :(
|
88
|
-
subordinate.should_not be_alive
|
89
|
-
|
90
|
-
new_subordinate = supervisor.actor
|
91
|
-
new_subordinate.should_not == subordinate
|
92
|
-
new_subordinate.state.should == :working
|
93
|
-
end
|
94
|
-
end
|