Class: Biryani::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/biryani/stream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tx, stream_id, proc) ⇒ Stream

Returns a new instance of Stream.

Parameters:

  • tx (Ractor::Port)
  • stream_id (Integer)
  • proc (Proc)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/biryani/stream.rb', line 8

def initialize(tx, stream_id, proc)
  @rx = Ractor.new(tx, stream_id, proc) do |tx, stream_id, proc|
    unless (req = Ractor.recv).nil?
      res = HTTP::Response.default

      begin
        proc.call(req, res)
        res.validate
      rescue StandardError => e
        puts e.backtrace
        res = HTTP::Response.internal_server_error
      end

      tx.send([res, stream_id], move: true)
    end
  end
end

Instance Attribute Details

#rxObject

Returns the value of attribute rx.



3
4
5
# File 'lib/biryani/stream.rb', line 3

def rx
  @rx
end