Method: Async::HTTP::Protocol::HTTP2::Connection#read_in_background

Defined in:
lib/async/http/protocol/http2/connection.rb

#read_in_background(parent: Task.current) ⇒ Object

Raises:

  • (RuntimeError)


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/async/http/protocol/http2/connection.rb', line 95

def read_in_background(parent: Task.current)
	raise RuntimeError, "Connection is closed!" if closed?
	
	parent.async(transient: true) do |task|
		@reader = task
		
		task.annotate("#{version} reading data for #{self.class}.")
		
		begin
			while !self.closed?
				self.consume_window
				self.read_frame
			end
		rescue SocketError, IOError, EOFError, Errno::ECONNRESET, Errno::EPIPE, Async::Wrapper::Cancelled
			# Ignore.
		ensure
			# Don't call #close twice.
			if @reader
				self.close($!)
			end
		end
	end
end