@@ -145,7 +145,7 @@ def promise(executor = :fast)
145
145
def join ( *futures )
146
146
countdown = Concurrent ::AtomicFixnum . new futures . size
147
147
promise = OuterPromise . new ( futures )
148
- futures . each { |future | future . add_callback :join , countdown , promise , *futures }
148
+ futures . each { |future | future . add_callback :join_callback , countdown , promise , *futures }
149
149
promise . future
150
150
end
151
151
end
@@ -345,6 +345,12 @@ def inspect
345
345
"#{ to_s [ 0 ..-2 ] } blocks:[#{ blocks . map ( &:to_s ) . join ( ', ' ) } ]>"
346
346
end
347
347
348
+ def join ( *futures )
349
+ ConcurrentNext . join self , *futures
350
+ end
351
+
352
+ alias_method :+ , :join
353
+
348
354
# @api private
349
355
def complete ( success , value , reason , raise = true ) # :nodoc:
350
356
callbacks = synchronize do
@@ -401,28 +407,24 @@ def set_promise_on_completion(promise)
401
407
promise . complete success? , value , reason
402
408
end
403
409
404
- def join ( countdown , promise , *futures )
410
+ def join_callback ( countdown , promise , *futures )
405
411
if success?
406
412
promise . success futures . map ( &:value ) if countdown . decrement . zero?
407
413
else
408
414
promise . try_fail reason
409
415
end
410
416
end
411
417
412
- def with_promise ( promise , &block )
413
- promise . evaluate_to &block
414
- end
415
-
416
418
def chain_callback ( executor , promise , callback )
417
- with_async ( executor ) { with_promise ( promise ) { callback_on_completion callback } }
419
+ with_async ( executor ) { promise . evaluate_to { callback_on_completion callback } }
418
420
end
419
421
420
422
def then_callback ( executor , promise , callback )
421
- with_async ( executor ) { with_promise ( promise ) { conditioned_callback callback } }
423
+ with_async ( executor ) { promise . evaluate_to { conditioned_callback callback } }
422
424
end
423
425
424
426
def rescue_callback ( executor , promise , callback )
425
- with_async ( executor ) { with_promise ( promise ) { callback_on_failure callback } }
427
+ with_async ( executor ) { promise . evaluate_to { callback_on_failure callback } }
426
428
end
427
429
428
430
def with_async ( executor )
@@ -725,6 +727,9 @@ def execute_once
725
727
branch1 = head . then ( &:succ ) . then ( &:succ )
726
728
branch2 = head . then ( &:succ ) . then_delay ( &:succ )
727
729
result = ConcurrentNext . join ( branch1 , branch2 ) . then { |b1 , b2 | b1 + b2 }
730
+ # other variants
731
+ result = branch1 . join ( branch2 ) . then { |b1 , b2 | b1 + b2 }
732
+ result = ( branch1 + branch2 ) . then { |b1 , b2 | b1 + b2 }
728
733
729
734
sleep 0.1
730
735
p branch1 . completed? , branch2 . completed? # true, false
0 commit comments