@@ -394,6 +394,24 @@ def get_ivar_from_args(opts)
394
394
395
395
expect ( composite ) . to be_rejected
396
396
end
397
+
398
+ it 'preserves ordering of the executed promises' do
399
+ 10 . times do
400
+ latch1 = CountDownLatch . new
401
+ latch2 = CountDownLatch . new
402
+ executor = SimpleExecutorService . new
403
+
404
+ p1 = Concurrent ::Promise . execute ( executor : executor ) { latch1 . wait ; 'one' }
405
+ p2 = Concurrent ::Promise . execute ( executor : executor ) { latch2 . wait ; 'two' }
406
+ p3 = Concurrent ::Promise . execute ( executor : executor ) { 'three' }
407
+
408
+ latch1 . count_down
409
+ latch2 . count_down
410
+
411
+ result = Concurrent ::Promise . zip ( p1 , p2 , p3 ) . value!
412
+ expect ( result ) . to eq ( [ 'one' , 'two' , 'three' ] )
413
+ end
414
+ end
397
415
end
398
416
399
417
describe '.zip' do
@@ -438,6 +456,27 @@ def get_ivar_from_args(opts)
438
456
439
457
expect ( composite ) . to be_rejected
440
458
end
459
+
460
+ it 'preserves ordering of the executed promises' do
461
+ promise1 = Promise . execute do
462
+ # resolves after the second promise
463
+ sleep 0.2
464
+ 'one'
465
+ end
466
+
467
+ promise2 = Promise . execute do
468
+ sleep 0.1
469
+ 'two'
470
+ end
471
+
472
+ promise3 = Promise . execute do
473
+ 'three'
474
+ end
475
+
476
+ result = Promise . zip ( promise1 , promise2 , promise3 ) . value
477
+
478
+ expect ( result ) . to eql ( [ 'one' , 'two' , 'three' ] )
479
+ end
441
480
end
442
481
443
482
describe 'aggregators' do
0 commit comments