Skip to content

Commit e7f8ab3

Browse files
committed
Fix Promise#zip for Promise<Array>
1 parent 47b5694 commit e7f8ab3

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/concurrent/promise.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ def flat_map(&block)
141141
#
142142
# @return [Promise]
143143
def zip(*others)
144-
others.reduce(self) do |p1, p2|
145-
p1.flat_map do |result1|
146-
p2.then do |result2|
147-
[result1, result2].flatten
144+
others.reduce(self.then { |x| [x] }) do |p1, p2|
145+
p1.flat_map do |results|
146+
p2.then do |next_result|
147+
results << next_result
148148
end
149149
end
150150
end

spec/concurrent/promise_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,12 @@ module Concurrent
294294
describe '#zip' do
295295
let(:promise1) { Promise.new(executor: executor) { 1 } }
296296
let(:promise2) { Promise.new(executor: executor) { 2 } }
297-
let(:promise3) { Promise.new(executor: executor) { 3 } }
297+
let(:promise3) { Promise.new(executor: executor) { [3] } }
298298

299299
it 'yields the results as an array' do
300300
composite = promise1.zip(promise2, promise3).execute
301301
sleep 0.1
302-
expect(composite.value).to eq([1,2,3])
302+
expect(composite.value).to eq([1, 2, [3]])
303303
end
304304

305305
it 'fails if one component fails' do

0 commit comments

Comments
 (0)