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

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Pipe.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/async/http/body/pipe.rb', line 33

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

Instance Method Details

#closeObject



53
54
55
56
57
58
# File 'lib/async/http/body/pipe.rb', line 53

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

#to_ioObject



49
50
51
# File 'lib/async/http/body/pipe.rb', line 49

def to_io
  @tail
end