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.

See Also:

Generic:

  • Elem

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headersHash{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.

Returns:

  • (Hash{String=>String})


35
36
37
# File 'lib/anthropic/internal/type/base_stream.rb', line 35

def headers
  @headers
end

#statusInteger (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.

Returns:

  • (Integer)


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.

Parameters:

  • stream (Enumerable<Object>)

Returns:

  • (Proc)

See Also:



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

#closevoid

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.

Parameters:

  • blk (Proc)

Yield Parameters:

  • (generic<Elem>)


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.

Parameters:

  • model (Class, Anthropic::Internal::Type::Converter)
  • url (URI::Generic)
  • status (Integer)
  • headers (Hash{String=>String})
  • response (Net::HTTPResponse)
  • unwrap (Symbol, Integer, Array<Symbol, Integer>, Proc)
  • stream (Enumerable<Object>)


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

#inspectString

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.

Returns:

  • (String)


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_enumEnumerator<generic<Elem>> Also known as: enum_for

Returns:

  • (Enumerator<generic<Elem>>)


63
# File 'lib/anthropic/internal/type/base_stream.rb', line 63

def to_enum = @iterator