File tree Expand file tree Collapse file tree 1 file changed +28
-14
lines changed Expand file tree Collapse file tree 1 file changed +28
-14
lines changed Original file line number Diff line number Diff line change @@ -370,24 +370,38 @@ def get_ivar_from_args(opts)
370
370
end
371
371
372
372
it 'preserves ordering of the executed promises' do
373
- promise1 = Promise . execute do
374
- # resolves after the second promise
375
- sleep 0.2
376
- 'one'
377
- end
373
+ 10 . times do
374
+ running = Mutex . new
375
+ cond = ConditionVariable . new
376
+ cond2 = ConditionVariable . new
377
+ executor = SimpleExecutorService . new
378
378
379
- promise2 = Promise . execute do
380
- sleep 0.1
381
- 'two'
382
- end
379
+ p1 = Concurrent ::Promise . execute ( executor : executor ) do
380
+ running . synchronize do
381
+ cond . wait ( running )
382
+ 'one'
383
+ end
384
+ end
383
385
384
- promise3 = Promise . execute do
385
- 'three'
386
- end
386
+ p2 = Concurrent ::Promise . execute ( executor : executor ) do
387
+ running . synchronize do
388
+ cond2 . wait ( running )
389
+ 'two'
390
+ end
391
+ end
387
392
388
- result = promise1 . zip ( promise2 , promise3 ) . value
393
+ p3 = Concurrent ::Promise . execute ( executor : executor ) do
394
+ running . synchronize do
395
+ 'three'
396
+ end
397
+ end
389
398
390
- expect ( result ) . to eql ( [ 'one' , 'two' , 'three' ] )
399
+ cond2 . signal
400
+ cond . signal
401
+
402
+ result = Concurrent ::Promise . zip ( p1 , p2 , p3 ) . value
403
+ expect ( result ) . to eq ( [ 'one' , 'two' , 'three' ] )
404
+ end
391
405
end
392
406
end
393
407
You can’t perform that action at this time.
0 commit comments