Class: Async::Enumerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/async/enumerator.rb

Overview

Wrapper providing async enumerable methods for parallel execution. See docs/reference/enumerator.md for detailed documentation.

Constant Summary

Constants included from Enumerable

Async::Enumerable::VERSION

Instance Method Summary collapse

Methods included from Enumerable

config_ref, included

Methods included from Async::Enumerable::Configurable

#__async_enumerable_collection, #__async_enumerable_collection_ref, #__async_enumerable_config_ref, #__async_enumerable_configure, #__async_enumerable_merge_all_config, included

Constructor Details

#initialize(enumerable = [], config = nil, **kwargs) ⇒ Enumerator

Creates async wrapper for enumerable.

Parameters:

  • enumerable (Enumerable) (defaults to: [])

    Object to wrap

  • config (Config, nil) (defaults to: nil)

    Configuration object

  • kwargs (Hash)

    Configuration options (max_fibers, etc.)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/async/enumerator.rb', line 14

def initialize(enumerable = [], config = nil, **kwargs)
  @enumerable = enumerable

  # Only configure if config or kwargs are provided
  if config || !kwargs.empty?
    __async_enumerable_configure do |cfg|
      # Merge config if provided
      config&.to_h&.each do |key, val|
        cfg[key] = val if val
      end

      # Merge kwargs if provided
      kwargs.each do |key, val|
        cfg[key] = val if val
      end
    end
  end
end