Class: FiberStream::RactorProducerGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/fiber_stream/ractor_producer.rb

Overview

Builder passed to ‘Source.ractor_merge_producers`.

Each ‘producer` call records one lazily started owned producer definition. Registration validates producer block isolation and transfer policy but does not create Ractor ports or start producer code.

Instance Method Summary collapse

Constructor Details

#initialize(default_transfer) ⇒ RactorProducerGroup

Returns a new instance of RactorProducerGroup.



147
148
149
150
# File 'lib/fiber_stream/ractor_producer.rb', line 147

def initialize(default_transfer)
  @default_transfer = default_transfer
  @definitions = []
end

Instance Method Details

#definitionsObject



163
164
165
# File 'lib/fiber_stream/ractor_producer.rb', line 163

def definitions
  @definitions.dup.freeze
end

#producer(*args, transfer: nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


152
153
154
155
156
157
158
159
160
161
# File 'lib/fiber_stream/ractor_producer.rb', line 152

def producer(*args, transfer: nil, &block)
  raise ArgumentError, "missing block" unless block
  unless transfer.nil? || [:copy, :move].include?(transfer)
    raise ArgumentError, "transfer must be :copy or :move"
  end
  raise TypeError, "block must be shareable" unless Ractor.shareable?(block)

  @definitions << Definition.new(args:, transfer: transfer || @default_transfer, block:)
  self
end