Class: Dizby::ServiceWorker
- Inherits:
-
Object
- Object
- Dizby::ServiceWorker
- Defined in:
- lib/dizby/worker/server.rb
Instance Method Summary collapse
- #accept_connection private
-
#initialize(server) ⇒ ServiceWorker
constructor
A new instance of ServiceWorker.
- #join
- #run private
Constructor Details
#initialize(server) ⇒ ServiceWorker
Returns a new instance of ServiceWorker.
12 13 14 15 |
# File 'lib/dizby/worker/server.rb', line 12 def initialize(server) @server = server @thread = Thread.start { run } end |
Instance Method Details
#accept_connection (private)
37 38 39 40 41 42 43 |
# File 'lib/dizby/worker/server.rb', line 37 def accept_connection connection = @server.accept return nil unless connection @server.add_uri_alias connection.remote_uri ConnectionWorker.new(@server, connection) end |
#join
17 18 19 |
# File 'lib/dizby/worker/server.rb', line 17 def join @thread.join if @thread end |
#run (private)
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dizby/worker/server.rb', line 23 def run connections = [] loop do conn = accept_connection connections << conn if conn end rescue LocalServerShutdown @server.log.debug('Server shutdown') ensure @server.close if @server.alive? connections.each(&:close) end |