class Async::HTTP::Body::Hijack

A body which is designed for hijacked connections.

def self.response(request, status, headers, &block)

def self.response(request, status, headers, &block)
	Async::HTTP::Response[status, headers, self.wrap(request, &block)]
end

def self.wrap(request, &block)

def self.wrap(request, &block)
	self.new(request.body, &block)
end

def call(stream)

def call(stream)
	return @block.call(stream)
ensure
	@block = nil
end

def empty?

Has the producer called #finish and has the reader consumed the nil token?
def empty?
	@block.nil?
end

def initialize(input = nil, &block)

def initialize(input = nil, &block)
	@input = input
	@block = block
	
	@task = nil
	@stream = nil
end

def inspect

def inspect
	"\#<#{self.class} #{@block}>"
end

def read

Read the next available chunk.
def read
	return unless @block
	
	unless @task
		@stream = Stream.new(@input)
		
		@task = Task.current.async do
			@block.call(@stream)
		end
		
		@block = nil
	end
	
	return @stream.output.read
end