File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -307,7 +307,16 @@ def self.execute(opts = {}, &block)
307307 # @yield The block operation to be performed asynchronously.
308308 #
309309 # @return [Promise] the new promise
310- def then ( rescuer = nil , executor = @executor , &block )
310+ def then ( *args , &block )
311+ if args . last . is_a? ( ::Hash )
312+ executor = args . pop [ :executor ]
313+ rescuer = args . first
314+ else
315+ rescuer , executor = args
316+ end
317+
318+ executor ||= @executor
319+
311320 raise ArgumentError . new ( 'rescuers and block are both missing' ) if rescuer . nil? && !block_given?
312321 block = Proc . new { |result | result } unless block_given?
313322 child = Promise . new (
Original file line number Diff line number Diff line change @@ -225,6 +225,13 @@ def get_ivar_from_args(opts)
225225 expect ( child ) . not_to be empty_root
226226 expect ( child . instance_variable_get ( :@executor ) ) . to be ( new_executor )
227227 end
228+
229+ it 'supports setting the executor using a named parameter' do
230+ new_executor = Concurrent ::SingleThreadExecutor . new
231+ child = empty_root . then ( executor : new_executor ) { nil }
232+ expect ( child . instance_variable_get ( :@executor ) ) . to be ( new_executor )
233+ end
234+
228235 it 'should have block or rescuers' do
229236 expect { empty_root . then } . to raise_error ( ArgumentError )
230237 end
You can’t perform that action at this time.
0 commit comments