Skip to content

Commit

Permalink
Renamed Actor#receive to Actor#act to align with Scala.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdantonio committed Oct 11, 2013
1 parent dce37c6 commit d9a7210
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
6 changes: 5 additions & 1 deletion lib/concurrent/actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def self.pool(count, &block)

protected

def act(*args)
raise NotImplementedError.new("#{self.class} does not implement #act")
end

class Poolbox

def initialize(queue)
Expand Down Expand Up @@ -71,7 +75,7 @@ def on_task # :nodoc:
message = @queue.pop
return if message == :stop
begin
result = receive(*message)
result = act(*message)
changed
notify_observers(Time.now, message, result)
rescue => ex
Expand Down
22 changes: 11 additions & 11 deletions spec/concurrent/actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(&block)
@task = block
super()
end
def receive(*message) # :nodoc:
def act(*message) # :nodoc:
@task.call(*message) unless @task.nil?
end
end
Expand Down Expand Up @@ -273,29 +273,29 @@ def update(*args) @notice = args; end
end
end

context '#receive overloading' do
context '#act overloading' do

let(:actor) do
Class.new(actor_clazz) {
attr_reader :last_message
def receive(*message)
def act(*message)
@last_message = message
end
}
end

it 'ignores the constructor block' do
@expected = false
channel = actor.new{|*args| @expected = true }
it 'raises an exception if #act is not implemented in the subclass' do
channel = Class.new(Actor).new
@thread = Thread.new{ channel.run }
@thread.join(0.1)
channel.post(:foo)
@thread.join(0.1)
@expected.should be_false
expect {
channel.post(:foo)
@thread.join(0.1)
}.to raise_error(NotImplementedError)
channel.stop
end

it 'uses the subclass receive implementation' do
it 'uses the subclass #act implementation' do
channel = actor.new{|*args| @expected = true }
@thread = Thread.new{ channel.run }
@thread.join(0.1)
Expand All @@ -311,7 +311,7 @@ def receive(*message)
let(:actor) do
Class.new(actor_clazz) {
attr_reader :last_error
def receive(*message)
def act(*message)
raise StandardError
end
def on_error(*args)
Expand Down

0 comments on commit d9a7210

Please sign in to comment.