Module: HTTPX::Plugins::FiberConcurrency::ConnectionMethods

Defined in:
lib/httpx/plugins/fiber_concurrency.rb,
sig/plugins/fiber_concurrency.rbs

Instance Method Summary collapse

Instance Method Details

#backlog?Boolean

checks whether the connection has any pending request (which the connection itself may have stored, or it may be somewhere in the parser).

Returns:

  • (Boolean)


119
120
121
122
# File 'lib/httpx/plugins/fiber_concurrency.rb', line 119

def backlog?
  @pending.any? ||
    (@parser && (@parser.pending.any? || @parser.requests.any?))
end

#current_context?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/httpx/plugins/fiber_concurrency.rb', line 67

def current_context?
  @pending.any?(&:current_context?) || (
    @sibling && @sibling.pending.any?(&:current_context?)
  )
end

#initial_callObject



73
74
75
76
77
# File 'lib/httpx/plugins/fiber_concurrency.rb', line 73

def initial_call
  return unless current_context?

  super
end

#interestsObject



79
80
81
82
83
# File 'lib/httpx/plugins/fiber_concurrency.rb', line 79

def interests
  return if connecting? && @pending.none?(&:current_context?)

  super
end

#on_connect_error(e) ⇒ Object



104
105
106
107
108
109
110
111
112
113
# File 'lib/httpx/plugins/fiber_concurrency.rb', line 104

def on_connect_error(e)
  return super unless e.is_a?(IOError) && e.message.include?("stream closed in another thread")

  # @fiber-switch-guard
  # sockets closed during fiber scheduler switches are raised in separate fibers than the fiber the
  # socket may be used in. this check verifies that this is actually about this socket.
  return unless to_io.closed? && !backlog?

  super
end

#on_io_error(e) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/httpx/plugins/fiber_concurrency.rb', line 85

def on_io_error(e)
  return super unless e.is_a?(IOError) && e.message.include?("stream closed in another thread")

  # @fiber-switch-guard
  # sockets closed during fiber scheduler switches are raised in separate fibers than the fiber the
  # socket may be used in. this check verifies that this is actually about this socket.
  return unless to_io.closed?

  if @state == :closing
    # @fiber-switch-guard
    # if the connection is reused across fibers, the socket may have been closed in the other fiber
    # and switched here during the process, so continue what it was doing and transition to closed
    # via #call.
    call
  elsif !backlog?
    super
  end
end

#sendvoid

This method returns an undefined value.

Parameters:

  • request (request)


19
# File 'sig/plugins/fiber_concurrency.rbs', line 19

def send: (request request) -> void