Permalink
Browse files

add an inline run strategy

  • Loading branch information...
1 parent 5d80356 commit db10b27101763f39d46075ded19bcf4bb845b1ff @svenfuchs svenfuchs committed Mar 13, 2013
Showing with 35 additions and 3 deletions.
  1. +2 −1 lib/travis/support/async.rb
  2. +14 −0 lib/travis/support/async/inline.rb
  3. +19 −2 spec/travis/async_spec.rb
@@ -3,6 +3,7 @@
module Travis
module Async
+ autoload :Inline, 'travis/support/async/inline'
autoload :Sidekiq, 'travis/support/async/sidekiq'
autoload :Threaded, 'travis/support/async/threaded'
@@ -30,7 +31,7 @@ def run(target, method, options, *args, &block)
end
def strategy(name)
- const_get(camelize(name || 'threaded'))
+ const_get(camelize(name || 'inline'))
end
def camelize(string)
@@ -0,0 +1,14 @@
+module Travis
+ module Async
+ module Inline
+ class << self
+ def run(target, method, options, *args, &block)
+ method.is_a?(Method) ? method.call(*args, &block) : target.send(method, *args, &block)
+ rescue Exception => e
+ puts "Exception caught in #{name}.call. Exceptions should be caught in client code"
+ puts e.message, e.backtrace
+ end
+ end
+ end
+ end
+end
View
@@ -44,7 +44,7 @@ def total_done
extend Travis::Async
def self.name; 'Class' end
def async_method; end
- async :async_method
+ async :async_method, use: :threaded
end
end
@@ -59,7 +59,7 @@ def async_method; end
Class.new do
extend Travis::Async
def async_method; end
- async :async_method
+ async :async_method, use: :threaded
end
end
@@ -75,6 +75,23 @@ def async_method; end
Travis::Async::Threaded.queues.should be_empty
end
end
+
+ describe 'Travis::Async::Inline' do
+ let(:target) do
+ Class.new do
+ def perform; end
+ end
+ end
+
+ it 'is the default strategy' do
+ Travis::Async.strategy(nil) == 'Inline'
+ end
+
+ it 'calls the method inline' do
+ target.expects(:perform).with(:foo)
+ Travis::Async.run(target, :perform, { use: :inline }, :foo)
+ end
+ end
end

0 comments on commit db10b27

Please sign in to comment.