Class: CDC::Parallel::Configuration

Inherits:
ConfigurationData
  • Object
show all
Defined in:
lib/cdc/parallel/configuration.rb,
sig/cdc/parallel/configuration.rbs

Overview

Immutable configuration for Ractor runtimes.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size: Etc.nprocessors, timeout: nil) ⇒ Configuration

Create a validated runtime configuration.

Parameters:

  • size (Integer) (defaults to: Etc.nprocessors)

    Worker count. Must be greater than zero.

  • timeout (Numeric, nil) (defaults to: nil)

    Optional timeout in seconds. Must be greater than zero when provided.

  • size: (Integer) (defaults to: Etc.nprocessors)
  • timeout: (Numeric, nil) (defaults to: nil)

Raises:

  • (ArgumentError)

    Raised when size or timeout is invalid.



39
40
41
42
43
44
45
46
47
# File 'lib/cdc/parallel/configuration.rb', line 39

def initialize(size: Etc.nprocessors, timeout: nil)
  raise ArgumentError, "size must be an Integer" unless size.is_a?(Integer)
  raise ArgumentError, "size must be greater than zero" unless size.positive?
  raise ArgumentError, "timeout must be numeric" unless timeout.nil? || timeout.is_a?(Numeric)
  raise ArgumentError, "timeout must be greater than zero" if timeout && !timeout.positive?

  super
  ::Ractor.make_shareable(self)
end

Instance Attribute Details

#sizeInteger (readonly)

Returns Number of worker Ractors to boot.

Returns:

  • (Integer)

    Number of worker Ractors to boot.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cdc/parallel/configuration.rb', line 29

class Configuration < ConfigurationData
  # Create a validated runtime configuration.
  #
  # @param size [Integer]
  #   Worker count. Must be greater than zero.
  # @param timeout [Numeric, nil]
  #   Optional timeout in seconds. Must be greater than zero when provided.
  # @raise [ArgumentError]
  #   Raised when `size` or `timeout` is invalid.
  # @return [void]
  def initialize(size: Etc.nprocessors, timeout: nil)
    raise ArgumentError, "size must be an Integer" unless size.is_a?(Integer)
    raise ArgumentError, "size must be greater than zero" unless size.positive?
    raise ArgumentError, "timeout must be numeric" unless timeout.nil? || timeout.is_a?(Numeric)
    raise ArgumentError, "timeout must be greater than zero" if timeout && !timeout.positive?

    super
    ::Ractor.make_shareable(self)
  end
end

#timeoutNumeric? (readonly)

Returns Optional wait timeout in seconds.

Returns:

  • (Numeric, nil)

    Optional wait timeout in seconds.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cdc/parallel/configuration.rb', line 29

class Configuration < ConfigurationData
  # Create a validated runtime configuration.
  #
  # @param size [Integer]
  #   Worker count. Must be greater than zero.
  # @param timeout [Numeric, nil]
  #   Optional timeout in seconds. Must be greater than zero when provided.
  # @raise [ArgumentError]
  #   Raised when `size` or `timeout` is invalid.
  # @return [void]
  def initialize(size: Etc.nprocessors, timeout: nil)
    raise ArgumentError, "size must be an Integer" unless size.is_a?(Integer)
    raise ArgumentError, "size must be greater than zero" unless size.positive?
    raise ArgumentError, "timeout must be numeric" unless timeout.nil? || timeout.is_a?(Numeric)
    raise ArgumentError, "timeout must be greater than zero" if timeout && !timeout.positive?

    super
    ::Ractor.make_shareable(self)
  end
end

Class Method Details

.newinstance

Parameters:

  • size: (Integer)
  • timeout: (Numeric, nil)

Returns:

  • (instance)


15
# File 'sig/cdc/parallel/configuration.rbs', line 15

def self.new: (?size: Integer, ?timeout: Numeric?) -> instance