Class: Async::HTTP::Body::Pipe

Inherits:
Object
  • Object
show all
Defined in:
lib/async/http/body/pipe.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, output = Writable.new, task: Task.current) ⇒ Pipe

If the input stream is closed first, it’s likely the output stream will also be closed.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/async/http/body/pipe.rb', line 14

def initialize(input, output = Writable.new, task: Task.current)
	@input = input
	@output = output
	
	head, tail = ::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
	
	@head = ::IO::Stream(head)
	@tail = tail
	
	@reader = nil
	@writer = nil
	
	task.async(transient: true, &self.method(:reader))
	task.async(transient: true, &self.method(:writer))
end

Instance Method Details

#closeObject



34
35
36
37
38
39
# File 'lib/async/http/body/pipe.rb', line 34

def close
	@reader&.stop
	@writer&.stop
	
	@tail.close
end

#to_ioObject



30
31
32
# File 'lib/async/http/body/pipe.rb', line 30

def to_io
	@tail
end