Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure a pool can be re-used

  • Loading branch information...
commit 9d962db0a97bc2d49a93a5519b591bdffefe2f79 1 parent 304507a
@jarib authored
Showing with 13 additions and 4 deletions.
  1. +13 −4 lib/vnctools/server_pool.rb
View
17 lib/vnctools/server_pool.rb
@@ -3,16 +3,21 @@ class ServerPool
include Observable
def initialize(capacity, klass = Server)
- @capacity = capacity
- @servers = Array.new(capacity) { klass.new }
- @running = []
+ @capacity = capacity
+ @running = []
+ @server_class = klass
+
+ create_servers
end
def stop
- running.each do |s|
+ running.dup.each do |s|
fire :on_display_stopping, s
s.stop
+ running.delete s
end
+
+ create_servers
end
def size
@@ -58,6 +63,10 @@ def next_server
server
end
+ def create_servers
+ @servers = Array.new(@capacity) { @server_class.new }
+ end
+
class TooManyDisplaysError < StandardError
end
Please sign in to comment.
Something went wrong with that request. Please try again.