@@ -79,7 +79,7 @@ module Concurrent
79
79
# ```
80
80
#
81
81
# Promises can be chained using the `then` method. The `then` method accepts a
82
- # block, to be executed on fulfillment, and a callable argument to be executed
82
+ # block and an executor , to be executed on fulfillment, and a callable argument to be executed
83
83
# on rejection. The result of the each promise is passed as the block argument
84
84
# to chained promises.
85
85
#
@@ -93,7 +93,7 @@ module Concurrent
93
93
# p = Concurrent::Promise.fulfill(20).
94
94
# then{|result| result - 10 }.
95
95
# then{|result| result * 3 }.
96
- # then{|result| result % 5 }.execute
96
+ # then(executor: different_executor) {|result| result % 5 }.execute
97
97
# ```
98
98
#
99
99
# The initial state of a newly created Promise depends on the state of its parent:
@@ -301,15 +301,18 @@ def self.execute(opts = {}, &block)
301
301
# @param [Proc] rescuer An optional rescue block to be executed if the
302
302
# promise is rejected.
303
303
#
304
+ # @param [ThreadPool] executor An optional thread pool executor to be used
305
+ # in the new Promise
306
+ #
304
307
# @yield The block operation to be performed asynchronously.
305
308
#
306
309
# @return [Promise] the new promise
307
- def then ( rescuer = nil , &block )
310
+ def then ( rescuer = nil , executor = @executor , &block )
308
311
raise ArgumentError . new ( 'rescuers and block are both missing' ) if rescuer . nil? && !block_given?
309
312
block = Proc . new { |result | result } unless block_given?
310
313
child = Promise . new (
311
314
parent : self ,
312
- executor : @ executor,
315
+ executor : executor ,
313
316
on_fulfill : block ,
314
317
on_reject : rescuer
315
318
)
0 commit comments