Permalink
Browse files

single threading fix: prevent ThreadError

error was thrown when Launchpad::Interaction#stop was called within an action response
  • Loading branch information...
1 parent ef46a88 commit 8100f924865d744f6eb06873ff6ac546f515dab0 Thomas Jachmann committed Feb 24, 2010
Showing with 24 additions and 1 deletion.
  1. +2 −0 README.rdoc
  2. +1 −1 lib/launchpad/interaction.rb
  3. +21 −0 test/test_interaction.rb
View
@@ -72,6 +72,8 @@ For more details, see the examples. examples/color_picker.rb is the most complex
== Changelog
+* single threading fix: prevent ThreadError when Launchpad::Interaction#stop is called within an action response
+
=== v.0.2.1
* Launchpad::Interaction#close now properly stops interaction first
@@ -90,7 +90,7 @@ def start(opts = nil)
@reader_thread ||= Thread.new do
begin
while @active do
- @device.read_pending_actions.each {|action| respond_to_action(action)}
+ @device.read_pending_actions.each {|action| Thread.new {respond_to_action(action)}}
sleep @latency unless @latency <= 0
end
rescue Portmidi::DeviceError => e
View
@@ -278,4 +278,25 @@ class TestInteraction < Test::Unit::TestCase
end
+ context 'regression tests' do
+
+ should 'not raise an exception when calling stop within a response in attached mode' do
+ i = Launchpad::Interaction.new
+ # strangely, you have to sleep 0.001 or do anything else before
+ # calling i.stop - the ThreadError won't be thrown otherwise...
+ i.response_to(:mixer, :down) {|i,a| sleep 0.001; i.stop}
+ i.device.stubs(:read_pending_actions).returns([{
+ :timestamp => 0,
+ :state => :down,
+ :type => :mixer
+ }])
+ assert_nothing_raised do
+ Thread.new do
+ i.start
+ end.join
+ end
+ end
+
+ end
+
end

0 comments on commit 8100f92

Please sign in to comment.