Skip to content

Commit

Permalink
Added ability for actors to receive the deliverable together with the…
Browse files Browse the repository at this point in the history
… payload.
  • Loading branch information
raphael committed Mar 31, 2009
1 parent cc63ae6 commit d0a838f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/nanite/dispatcher.rb
Expand Up @@ -14,12 +14,15 @@ def initialize(amq, registry, serializer, identity, options)

def dispatch(deliverable)
prefix, meth = deliverable.type.split('/')[1..-1]
meth ||= :index
actor = registry.actor_for(prefix)

@evmclass.defer(lambda {
begin
intermediate_results_proc = lambda { |*args| self.handle_intermediate_results(actor, meth, deliverable, *args) }
actor.send((meth.nil? ? :index : meth), deliverable.payload, &intermediate_results_proc)
args = [ deliverable.payload ]
args.push(deliverable) if actor.method(meth).arity == 2
actor.send(meth, *args, &intermediate_results_proc)
rescue Exception => e
handle_exception(actor, meth, deliverable, e)
end
Expand Down
12 changes: 12 additions & 0 deletions spec/dispatcher_spec.rb
Expand Up @@ -13,6 +13,10 @@ def index(payload)
def bar(payload)
['hello', payload]
end

def bar2(payload, deliverable)
deliverable
end

def i_kill_you(payload)
raise RuntimeError.new('I kill you!')
Expand Down Expand Up @@ -73,6 +77,14 @@ def self.defer(op = nil, callback = nil)
res.results.should == ['hello', 'you']
end

it "should dispatch the deliverable to actions that accept it" do
req = Nanite::Request.new('/foo/bar2', 'you')
res = @dispatcher.dispatch(req)
res.should(be_kind_of(Nanite::Result))
res.token.should == req.token
res.results.should == req
end

it "should dispatch a request to the default action" do
req = Nanite::Request.new('/foo', 'you')
res = @dispatcher.dispatch(req)
Expand Down

0 comments on commit d0a838f

Please sign in to comment.