@@ -79,7 +79,7 @@ module Concurrent
7979 # ```
8080 #
8181 # 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
8383 # on rejection. The result of the each promise is passed as the block argument
8484 # to chained promises.
8585 #
@@ -93,7 +93,7 @@ module Concurrent
9393 # p = Concurrent::Promise.fulfill(20).
9494 # then{|result| result - 10 }.
9595 # then{|result| result * 3 }.
96- # then{|result| result % 5 }.execute
96+ # then(executor: different_executor) {|result| result % 5 }.execute
9797 # ```
9898 #
9999 # The initial state of a newly created Promise depends on the state of its parent:
@@ -301,15 +301,18 @@ def self.execute(opts = {}, &block)
301301 # @param [Proc] rescuer An optional rescue block to be executed if the
302302 # promise is rejected.
303303 #
304+ # @param [ThreadPool] executor An optional thread pool executor to be used
305+ # in the new Promise
306+ #
304307 # @yield The block operation to be performed asynchronously.
305308 #
306309 # @return [Promise] the new promise
307- def then ( rescuer = nil , &block )
310+ def then ( rescuer = nil , executor = @executor , &block )
308311 raise ArgumentError . new ( 'rescuers and block are both missing' ) if rescuer . nil? && !block_given?
309312 block = Proc . new { |result | result } unless block_given?
310313 child = Promise . new (
311314 parent : self ,
312- executor : @ executor,
315+ executor : executor ,
313316 on_fulfill : block ,
314317 on_reject : rescuer
315318 )
0 commit comments