Method: Concurrent::Promise#then
- Defined in:
- lib/concurrent-ruby/concurrent/promise.rb
#then(rescuer, executor, &block) ⇒ Promise #then(rescuer, executor: executor, &block) ⇒ Promise
Chain a new promise off the current promise.
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/concurrent-ruby/concurrent/promise.rb', line 314 def then(*args, &block) if args.last.is_a?(::Hash) executor = args.pop[:executor] rescuer = args.first else rescuer, executor = args end executor ||= @executor raise ArgumentError.new('rescuers and block are both missing') if rescuer.nil? && !block_given? block = Proc.new { |result| result } unless block_given? child = Promise.new( parent: self, executor: executor, on_fulfill: block, on_reject: rescuer ) synchronize do child.state = :pending if @state == :pending child.on_fulfill((@value)) if @state == :fulfilled child.on_reject(@reason) if @state == :rejected @children << child end child end |