Skip to content
Browse files

first shot at re-enabling callback style

  • Loading branch information...
1 parent afea78e commit 61e53a3f13be5fca723670eb1c620e0442fb07d1 @vangberg committed Jan 29, 2012
Showing with 22 additions and 21 deletions.
  1. +12 −12 lib/librevox/listener/outbound.rb
  2. +5 −5 spec/helper.rb
  3. +5 −4 spec/librevox/listener/spec_outbound.rb
View
24 lib/librevox/listener/outbound.rb
@@ -6,20 +6,20 @@ module Listener
class Outbound < Base
include Librevox::Applications
- def application app, args=nil, params={}
+ def application app, args=nil, params={}, &block
msg = "sendmsg\n"
msg << "call-command: execute\n"
msg << "execute-app-name: #{app}\n"
msg << "execute-app-arg: #{args}\n" if args && !args.empty?
send_data "#{msg}\n"
- @application_queue << Fiber.current
-
- Fiber.yield
- update_session
-
- params[:variable] ? variable(params[:variable]) : nil
+ @application_queue.push(proc {
+ update_session do
+ arg = params[:variable] ? variable(params[:variable]) : nil
+ block.call(arg) if block
+ end
+ })
end
# This should probably be in Application#sendmsg instead.
@@ -40,9 +40,9 @@ def post_init
send_data "connect\n\n"
send_data "myevents\n\n"
- @application_queue << Fiber.new {}
+ @application_queue << proc {}
send_data "linger\n\n"
- @application_queue << Fiber.new {session_initiated}
+ @application_queue << proc {session_initiated}
end
def handle_response
@@ -51,7 +51,7 @@ def handle_response
elsif response.event? && response.event == "CHANNEL_DATA"
@session = response.content
elsif response.command_reply? && !response.event?
- @application_queue.shift.resume if @application_queue.any?
+ @application_queue.shift.call(response) if @application_queue.any?
end
super
@@ -61,8 +61,8 @@ def variable name
session[:"variable_#{name}"]
end
- def update_session
- api.command "uuid_dump", session[:unique_id]
+ def update_session &block
+ api.command "uuid_dump", session[:unique_id], &block
end
end
end
View
10 spec/helper.rb
@@ -4,17 +4,17 @@
module Librevox::Test
module Matchers
def send_command command
- lambda {|obj|
+ proc {|obj|
obj.outgoing_data.shift.should == "#{command}\n\n"
}
end
def send_nothing
- lambda {|obj| obj.outgoing_data.shift.should == nil}
+ proc {|obj| obj.outgoing_data.shift.should == nil}
end
def send_application app, args=nil
- lambda {|obj|
+ proc {|obj|
msg = <<-EOM
sendmsg
call-command: execute
@@ -29,11 +29,11 @@ def send_application app, args=nil
def update_session session_id=nil
if session_id
- lambda {|obj|
+ proc {|obj|
obj.outgoing_data.shift.should == "api uuid_dump #{session_id}\n\n"
}
else
- lambda {|obj|
+ proc {|obj|
obj.outgoing_data.shift.should.match /^api uuid_dump \d+/
}
end
View
9 spec/librevox/listener/spec_outbound.rb
@@ -4,8 +4,8 @@
require 'librevox/listener/outbound'
module Librevox::Applications
- def sample_app name, *args
- application name, args.join(" ")
+ def sample_app name, *args, &block
+ application name, args.join(" "), &block
end
end
@@ -61,8 +61,9 @@ def event_and_linger_replies
class OutboundListenerWithNestedApps < Librevox::Listener::Outbound
def session_initiated
- sample_app "foo"
- sample_app "bar"
+ sample_app "foo" do
+ sample_app "bar"
+ end
end
end

0 comments on commit 61e53a3

Please sign in to comment.
Something went wrong with that request. Please try again.