Class: RightSpeed::Processor::FairProcessor

Inherits:
Base
  • Object
show all
Defined in:
lib/right_speed/processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(workers, handler) ⇒ FairProcessor

Returns a new instance of FairProcessor.



100
101
102
103
104
105
# File 'lib/right_speed/processor.rb', line 100

def initialize(workers, handler)
  @worker_num = workers
  @handler = handler
  @workers = workers.times.map{|i| Worker::Fair.new(id: i, handler: @handler)}
  @closer = ConnectionCloser.new
end

Instance Method Details

#configure(listener:) ⇒ Object



107
108
109
# File 'lib/right_speed/processor.rb', line 107

def configure(listener:)
  @listener = listener
end

#process(conn) ⇒ Object



117
118
119
# File 'lib/right_speed/processor.rb', line 117

def process(conn)
  Ractor.yield(conn, move: true)
end

#runObject



111
112
113
114
115
# File 'lib/right_speed/processor.rb', line 111

def run
  @listener.run(self)
  @workers.each{|w| w.run(@listener.ractor)}
  @closer.run(@workers.map{|w| w.ractor})
end

#waitObject



121
122
123
124
# File 'lib/right_speed/processor.rb', line 121

def wait
  # listener, workers are using those outgoing to pass connections
  @closer.wait
end