Class: Grocer::Server
- Inherits:
-
Object
- Object
- Grocer::Server
- Defined in:
- lib/grocer/server.rb
Instance Attribute Summary collapse
-
#notifications ⇒ Object
readonly
Returns the value of attribute notifications.
Instance Method Summary collapse
- #accept ⇒ Object
- #close ⇒ Object
-
#initialize(server) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(server) ⇒ Server
Returns a new instance of Server.
9 10 11 12 13 14 |
# File 'lib/grocer/server.rb', line 9 def initialize(server) @server = server @clients = [] @notifications = Queue.new end |
Instance Attribute Details
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
7 8 9 |
# File 'lib/grocer/server.rb', line 7 def notifications @notifications end |
Instance Method Details
#accept ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/grocer/server.rb', line 16 def accept Thread.new { begin @server.accept { |client| @clients << client Thread.new { begin NotificationReader.new(client).each(¬ifications.method(:push)) rescue Errno::EBADF, NoMethodError # Expected when another thread closes the socket end } } rescue Errno::EBADF # Expected when another thread closes the socket end } end |
#close ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/grocer/server.rb', line 36 def close if @server @server.close @server = nil end @clients.each(&:close) @clients = [] end |