Method: Baml::BamlStream#each

Defined in:
lib/stream.rb

#each(&block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/stream.rb', line 63

def each(&block)
  # Implementing this and include-ing Enumerable allows users to treat this as a Ruby
  # collection: https://ruby-doc.org/3.1.6/Enumerable.html#module-Enumerable-label-Usage
  if @final_response == nil
    @final_response = @ffi_stream.done(@ctx_manager) do |event|
      block.call event.parsed_using_types(Baml::Types, Baml::PartialTypes, true)
    end
  end

  self
end