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)
307
307
# @yield The block operation to be performed asynchronously.
308
308
#
309
309
# @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
+
311
320
raise ArgumentError . new ( 'rescuers and block are both missing' ) if rescuer . nil? && !block_given?
312
321
block = Proc . new { |result | result } unless block_given?
313
322
child = Promise . new (
Original file line number Diff line number Diff line change @@ -225,6 +225,13 @@ def get_ivar_from_args(opts)
225
225
expect ( child ) . not_to be empty_root
226
226
expect ( child . instance_variable_get ( :@executor ) ) . to be ( new_executor )
227
227
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
+
228
235
it 'should have block or rescuers' do
229
236
expect { empty_root . then } . to raise_error ( ArgumentError )
230
237
end
You can’t perform that action at this time.
0 commit comments