Module: OpenAI::Internal::Type::BaseStream Private
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
This module provides a base implementation for streaming responses in the SDK.
Class Method Summary collapse
-
.defer_closing(stream) ⇒ Proc
private
Attempt to close the underlying transport when the stream itself is garbage collected.
Instance Method Summary collapse
- #close ⇒ void
- #each(&blk) {|| ... } ⇒ void
- #initialize(model:, url:, status:, response:, stream:) ⇒ Object private
- #inspect ⇒ String private
- #to_enum ⇒ Enumerator<generic<Elem>> (also: #enum_for)
Class Method Details
.defer_closing(stream) ⇒ Proc
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Attempt to close the underlying transport when the stream itself is garbage collected.
This should not be relied upon for resource clean up, as the garbage collector is not guaranteed to run.
28 |
# File 'lib/openai/internal/type/base_stream.rb', line 28 def defer_closing(stream) = ->(_id) { OpenAI::Internal::Util.close_fused!(stream) } |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
34 |
# File 'lib/openai/internal/type/base_stream.rb', line 34 def close = OpenAI::Internal::Util.close_fused!(@iterator) |
#each(&blk) {|| ... } ⇒ void
This method returns an undefined value.
47 48 49 50 51 52 |
# File 'lib/openai/internal/type/base_stream.rb', line 47 def each(&blk) unless block_given? raise ArgumentError.new("A block must be given to ##{__method__}") end @iterator.each(&blk) end |
#initialize(model:, url:, status:, response:, stream:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/openai/internal/type/base_stream.rb', line 68 def initialize(model:, url:, status:, response:, stream:) @model = model @url = url @status = status @response = response @stream = stream @iterator = iterator ObjectSpace.define_finalizer(self, OpenAI::Internal::Type::BaseStream.defer_closing(@stream)) end |
#inspect ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 85 86 |
# File 'lib/openai/internal/type/base_stream.rb', line 82 def inspect model = OpenAI::Internal::Type::Converter.inspect(@model, depth: 1) "#<#{self.class}[#{model}]:0x#{object_id.to_s(16)}>" end |
#to_enum ⇒ Enumerator<generic<Elem>> Also known as: enum_for
57 |
# File 'lib/openai/internal/type/base_stream.rb', line 57 def to_enum = @iterator |