Class: Async::HTTP::Protocol::HTTP1::Finishable

Inherits:
Protocol::HTTP::Body::Wrapper
  • Object
show all
Defined in:
lib/async/http/protocol/http1/finishable.rb

Overview

Keeps track of whether a body is being read, and if so, waits for it to be closed.

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Finishable

Returns a new instance of Finishable.



15
16
17
18
19
20
21
22
# File 'lib/async/http/protocol/http1/finishable.rb', line 15

def initialize(body)
	super(body)
	
	@closed = Async::Variable.new
	@error = nil
	
	@reading = false
end

Instance Method Details

#close(error = nil) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/async/http/protocol/http1/finishable.rb', line 34

def close(error = nil)
	super
	
	unless @closed.resolved?
		@error = error
		@closed.value = true
	end
end

#inspectObject



55
56
57
# File 'lib/async/http/protocol/http1/finishable.rb', line 55

def inspect
	"#<#{self.class} closed=#{@closed} error=#{@error}> | #{super}"
end

#readObject



28
29
30
31
32
# File 'lib/async/http/protocol/http1/finishable.rb', line 28

def read
	@reading = true
	
	super
end

#reading?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/async/http/protocol/http1/finishable.rb', line 24

def reading?
	@reading
end

#wait(persistent = true) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/async/http/protocol/http1/finishable.rb', line 43

def wait(persistent = true)
	if @reading
		@closed.wait
	elsif persistent
		# If the connection can be reused, let's gracefully discard the body:
		self.discard
	else
		# Else, we don't care about the body, so we can close it immediately:
		self.close
	end
end