Class: Adelnor::AsyncServer

Inherits:
BaseServer show all
Defined in:
lib/adelnor/async_server.rb

Instance Method Summary collapse

Methods inherited from BaseServer

#handle, #rack_data, #read_request_message, run, #welcome_message

Constructor Details

#initialize(rack_app, port, options = {}) ⇒ AsyncServer

Returns a new instance of AsyncServer.



9
10
11
12
13
14
# File 'lib/adelnor/async_server.rb', line 9

def initialize(rack_app, port, options = {})
  super(rack_app, port, options)

  scheduler = Async::Scheduler.new
  Fiber.set_scheduler(scheduler)
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/adelnor/async_server.rb', line 16

def run
  Async do |task|
    loop do
      client, = @socket.accept

      task.async do
        handle(client)
        client.close
      end
    end
  end
end