Skip to content

Commit 8a84b9a

Browse files
hanazukipitr-ch
authored andcommitted
Let Promises.any_fulfilled_future take an Event
This patch teaches `Promises.any_fulfilled_future` to treat a resolved `Event` as a fulfilled `Future` value of `nil`. Closes: #963 Co-authored-by: Petr Chalupa <[email protected]>
1 parent 7884d5e commit 8a84b9a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/concurrent-ruby/concurrent/promises.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,8 +2074,8 @@ class AnyFulfilledFuturePromise < AnyResolvedFuturePromise
20742074

20752075
private
20762076

2077-
def resolvable?(countdown, future, index)
2078-
future.fulfilled? ||
2077+
def resolvable?(countdown, event_or_future, index)
2078+
(event_or_future.is_a?(Event) ? event_or_future.resolved? : event_or_future.fulfilled?) ||
20792079
# inlined super from BlockedPromise
20802080
countdown.zero?
20812081
end

spec/concurrent/promises_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,24 @@ def behaves_as_delay(delay, value)
157157

158158
expect(any.value!).to eq :value
159159
end
160+
161+
it 'treats a resolved Event as a fulfilled Future' do
162+
any = any_fulfilled_future(
163+
resolved_event,
164+
fulfilled_future(:value),
165+
)
166+
167+
expect(any.value!).to eq nil
168+
end
169+
170+
it 'treats a pending Event as a pending Future' do
171+
any = any_fulfilled_future(
172+
resolvable_event,
173+
fulfilled_future(:value),
174+
)
175+
176+
expect(any.value!).to eq :value
177+
end
160178
end
161179

162180
describe '.zip' do

0 commit comments

Comments
 (0)