Skip to content

Commit 94d19cd

Browse files
iankspitr-ch
authored andcommitted
Add specs for Promise#zip/Promise.zip ordering
1 parent 50ed4a5 commit 94d19cd

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

spec/concurrent/promise_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,27 @@ def get_ivar_from_args(opts)
368368

369369
expect(composite).to be_rejected
370370
end
371+
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
378+
379+
promise2 = Promise.execute do
380+
sleep 0.1
381+
'two'
382+
end
383+
384+
promise3 = Promise.execute do
385+
'three'
386+
end
387+
388+
result = promise1.zip(promise2, promise3).value
389+
390+
expect(result).to eql(['one', 'two', 'three'])
391+
end
371392
end
372393

373394
describe '.zip' do
@@ -386,6 +407,27 @@ def get_ivar_from_args(opts)
386407

387408
expect(composite).to be_rejected
388409
end
410+
411+
it 'preserves ordering of the executed promises' do
412+
promise1 = Promise.execute do
413+
# resolves after the second promise
414+
sleep 0.2
415+
'one'
416+
end
417+
418+
promise2 = Promise.execute do
419+
sleep 0.1
420+
'two'
421+
end
422+
423+
promise3 = Promise.execute do
424+
'three'
425+
end
426+
427+
result = Promise.zip(promise1, promise2, promise3).value
428+
429+
expect(result).to eql(['one', 'two', 'three'])
430+
end
389431
end
390432

391433
describe 'aggregators' do

0 commit comments

Comments
 (0)