Module: Async::Enumerable::Methods::Predicates::Any
- Defined in:
- lib/async/enumerable/methods/predicates/any.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#any?(pattern = nil) {|item| ... } ⇒ Boolean
Returns true if any element satisfies the condition (parallel, early termination).
Class Method Details
.included(base) ⇒ Object
8 9 10 11 12 |
# File 'lib/async/enumerable/methods/predicates/any.rb', line 8 def self.included(base) base.include(::Enumerable) # Dependency base.include(Configurable) # Dependency for collection resolution base.include(ConcurrencyBounder) # Dependency end |
Instance Method Details
#any?(pattern = nil) {|item| ... } ⇒ Boolean
Returns true if any element satisfies the condition (parallel, early termination).
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/async/enumerable/methods/predicates/any.rb', line 17 def any?(pattern = nil, &block) # Delegate pattern/no-block cases to wrapped enumerable to avoid break issues if pattern return __async_enumerable_collection.any?(pattern) elsif !block_given? return __async_enumerable_collection.any? end found = Concurrent::AtomicBoolean.new(false) __async_enumerable_bounded_concurrency(early_termination: true) do || __async_enumerable_collection.each do |item| break if found.true? .async do if block.call(item) found.make_true # Stop the barrier early when we find a match .stop end end end end found.true? end |