Class: CDC::Parallel::Configuration
- Inherits:
-
Object
- Object
- CDC::Parallel::Configuration
- Defined in:
- lib/cdc/parallel/configuration.rb
Overview
Immutable configuration shared by cdc-parallel runtime objects.
‘Configuration` validates worker sizing and timeout values at construction time, freezes the resulting data object through `Data.define`, and makes the instance shareable so it is safe to retain around Ractor-oriented runtime objects.
Instance Attribute Summary collapse
-
#size ⇒ Integer
readonly
Number of worker Ractors to boot.
-
#timeout ⇒ Numeric?
readonly
Optional wait timeout in seconds.
Instance Method Summary collapse
-
#initialize(size: Etc.nprocessors, timeout: nil) ⇒ void
constructor
Create a validated runtime configuration.
Constructor Details
#initialize(size: Etc.nprocessors, timeout: nil) ⇒ void
Create a validated runtime configuration.
35 36 37 38 39 40 41 42 43 |
# File 'lib/cdc/parallel/configuration.rb', line 35 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
#size ⇒ Integer (readonly)
Returns Number of worker Ractors to boot.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cdc/parallel/configuration.rb', line 25 class Configuration < Data.define(:size, :timeout) # 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 |
#timeout ⇒ Numeric? (readonly)
Returns Optional wait timeout in seconds.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cdc/parallel/configuration.rb', line 25 class Configuration < Data.define(:size, :timeout) # 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 |