Class: Async::HTTP::Protocol::HTTP2::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/async/http/protocol/http2/output.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream, body) ⇒ Output

Returns a new instance of Output.



38
39
40
41
42
43
44
# File 'lib/async/http/protocol/http2/output.rb', line 38

def initialize(stream, body)
	@stream = stream
	@body = body
	@task = nil
	
	@window_updated = Async::Condition.new
end

Class Method Details

.for(stream, body) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/async/http/protocol/http2/output.rb', line 30

def self.for(stream, body)
	output = self.new(stream, body)
	
	output.start
	
	return output
end

Instance Method Details

#close(error = nil) ⇒ Object



74
75
76
# File 'lib/async/http/protocol/http2/output.rb', line 74

def close(error = nil)
	@stream.finish_output(error)
end

#start(parent: Task.current) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/async/http/protocol/http2/output.rb', line 46

def start(parent: Task.current)
	raise "Task already started!" if @task
	
	if @body.respond_to?(:call)
		@task = parent.async(&self.method(:stream))
	else
		@task = parent.async(&self.method(:passthrough))
	end
end

#stop(error) ⇒ Object



78
79
80
81
# File 'lib/async/http/protocol/http2/output.rb', line 78

def stop(error)
	@task&.stop
	@task = nil
end

#window_updated(size) ⇒ Object



56
57
58
# File 'lib/async/http/protocol/http2/output.rb', line 56

def window_updated(size)
	@window_updated.signal
end

#write(chunk) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/async/http/protocol/http2/output.rb', line 60

def write(chunk)
	until chunk.empty?
		maximum_size = @stream.available_frame_size
		
		while maximum_size <= 0
			@window_updated.wait
			
			maximum_size = @stream.available_frame_size
		end
		
		break unless chunk = send_data(chunk, maximum_size)
	end
end