Skip to content

Commit 4fb4b7d

Browse files
committed
Removed Promise.one? and Promise.none?
The original request was for .any? and .all? methods. We added .none? and .one? methods for synergy with arrays, but didn't like that these methods supressed exceptions. So we decided to add only the requested methods and consider other methods in the future.
1 parent bf0bc6f commit 4fb4b7d

File tree

2 files changed

+0
-132
lines changed

2 files changed

+0
-132
lines changed

lib/concurrent/promise.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -363,28 +363,6 @@ def self.any?(*promises)
363363
aggregate(:any?, *promises)
364364
end
365365

366-
# Aggregates a collection of promises and executes the `then` condition
367-
# if all aggregated promises fail. Executes the `rescue` handler with
368-
# a `Concurrent::PromiseExecutionError` if any of the aggregated promises
369-
# succeed. Upon execution will execute any of the aggregate promises that
370-
# were not already executed.
371-
#
372-
# @!macro promise_self_aggregate
373-
def self.none?(*promises)
374-
aggregate(:none?, *promises)
375-
end
376-
377-
# Aggregates a collection of promises and executes the `then` condition
378-
# if one and only one of the aggregated promises succeeds. Executes the
379-
# `rescue` handler with a `Concurrent::PromiseExecutionError` more than one
380-
# of the aggregated promises succeed. Upon execution will execute any of
381-
# the aggregate promises that were not already executed.
382-
#
383-
# @!macro promise_self_aggregate
384-
def self.one?(*promises)
385-
aggregate(:one?, *promises)
386-
end
387-
388366
protected
389367

390368
# Aggregate a collection of zero or more promises under a composite promise,

spec/concurrent/promise_spec.rb

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -448,116 +448,6 @@ module Concurrent
448448
expect(counter.value).to eq -1
449449
end
450450
end
451-
452-
describe '.none?' do
453-
454-
it 'returns a new Promise' do
455-
composite = Promise.none?(promise1, promise2, promise3).execute
456-
expect(composite).to be_a Concurrent::Promise
457-
end
458-
459-
it 'does not execute the returned Promise' do
460-
composite = Promise.none?(promise1, promise2, promise3)
461-
expect(composite).to be_unscheduled
462-
end
463-
464-
it 'executes the #then condition when all components fail' do
465-
counter = Concurrent::AtomicFixnum.new(0)
466-
latch = Concurrent::CountDownLatch.new(1)
467-
468-
composite = Promise.none?(rejected_subject, rejected_subject, rejected_subject, rejected_subject).
469-
then { counter.up; latch.count_down }.
470-
rescue { counter.down; latch.count_down }.
471-
execute
472-
473-
latch.wait(1)
474-
475-
expect(counter.value).to eq 1
476-
end
477-
478-
it 'executes the #then condition when no promises are given' do
479-
counter = Concurrent::AtomicFixnum.new(0)
480-
latch = Concurrent::CountDownLatch.new(1)
481-
482-
composite = Promise.none?.
483-
then { counter.up; latch.count_down }.
484-
rescue { counter.down; latch.count_down }.
485-
execute
486-
487-
latch.wait(1)
488-
489-
expect(counter.value).to eq 1
490-
end
491-
492-
it 'executes the #rescue handler if even one component succeeds' do
493-
counter = Concurrent::AtomicFixnum.new(0)
494-
latch = Concurrent::CountDownLatch.new(1)
495-
496-
composite = Promise.none?(promise1, promise2, rejected_subject, promise3).
497-
then { counter.up; latch.count_down }.
498-
rescue { counter.down; latch.count_down }.
499-
execute
500-
501-
latch.wait(1)
502-
503-
expect(counter.value).to eq -1
504-
end
505-
end
506-
507-
describe '.one?' do
508-
509-
it 'returns a new Promise' do
510-
composite = Promise.one?(promise1, promise2, promise3).execute
511-
expect(composite).to be_a Concurrent::Promise
512-
end
513-
514-
it 'does not execute the returned Promise' do
515-
composite = Promise.one?(promise1, promise2, promise3)
516-
expect(composite).to be_unscheduled
517-
end
518-
519-
it 'executes the #then condition when only one component succeeds' do
520-
counter = Concurrent::AtomicFixnum.new(0)
521-
latch = Concurrent::CountDownLatch.new(1)
522-
523-
composite = Promise.one?(promise1, rejected_subject, rejected_subject, rejected_subject).
524-
then { counter.up; latch.count_down }.
525-
rescue { counter.down; latch.count_down }.
526-
execute
527-
528-
latch.wait(1)
529-
530-
expect(counter.value).to eq 1
531-
end
532-
533-
it 'executes the #then condition when no promises are given' do
534-
counter = Concurrent::AtomicFixnum.new(0)
535-
latch = Concurrent::CountDownLatch.new(1)
536-
537-
composite = Promise.one?.
538-
then { counter.up; latch.count_down }.
539-
rescue { counter.down; latch.count_down }.
540-
execute
541-
542-
latch.wait(1)
543-
544-
expect(counter.value).to eq 1
545-
end
546-
547-
it 'executes the #rescue handler if two or more components succeed' do
548-
counter = Concurrent::AtomicFixnum.new(0)
549-
latch = Concurrent::CountDownLatch.new(1)
550-
551-
composite = Promise.one?(promise1, promise2, rejected_subject, promise3).
552-
then { counter.up; latch.count_down }.
553-
rescue { counter.down; latch.count_down }.
554-
execute
555-
556-
latch.wait(1)
557-
558-
expect(counter.value).to eq -1
559-
end
560-
end
561451
end
562452

563453
context 'fulfillment' do

0 commit comments

Comments
 (0)