Module: Anthropic::Internal::Type::BaseStream Private
- Includes:
- Enumerable
- Included in:
- Helpers::Streaming::MessageStream, JsonLStream, Stream
- Defined in:
- lib/anthropic/internal/type/base_stream.rb
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.
Instance Attribute Summary collapse
- #headers ⇒ Hash{String=>String} readonly private
- #status ⇒ Integer readonly private
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:, headers:, response:, unwrap:, stream:) ⇒ void private
- #inspect ⇒ String private
- #to_enum ⇒ Enumerator<generic<Elem>> (also: #enum_for)
Instance Attribute Details
#headers ⇒ Hash{String=>String} (readonly)
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.
35 36 37 |
# File 'lib/anthropic/internal/type/base_stream.rb', line 35 def headers @headers end |
#status ⇒ Integer (readonly)
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.
32 33 34 |
# File 'lib/anthropic/internal/type/base_stream.rb', line 32 def status @status end |
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/anthropic/internal/type/base_stream.rb', line 28 def defer_closing(stream) = ->(_id) { Anthropic::Internal::Util.close_fused!(stream) } |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
40 |
# File 'lib/anthropic/internal/type/base_stream.rb', line 40 def close = Anthropic::Internal::Util.close_fused!(@iterator) |
#each(&blk) {|| ... } ⇒ void
This method returns an undefined value.
53 54 55 56 57 58 |
# File 'lib/anthropic/internal/type/base_stream.rb', line 53 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:, headers:, response:, unwrap:, stream:) ⇒ void
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.
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/anthropic/internal/type/base_stream.rb', line 76 def initialize(model:, url:, status:, headers:, response:, unwrap:, stream:) @model = model @url = url @status = status @headers = headers @response = response @unwrap = unwrap @stream = stream @iterator = iterator ObjectSpace.define_finalizer(self, Anthropic::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.
92 93 94 95 96 |
# File 'lib/anthropic/internal/type/base_stream.rb', line 92 def inspect model = Anthropic::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
63 |
# File 'lib/anthropic/internal/type/base_stream.rb', line 63 def to_enum = @iterator |