             self.maxConnections = 100
         }
         self.maxRequests = self.maxConnections
+        self.isThreaded = threaded
+        
+        if threaded {
+            self.connectionsQueue = NSOperationQueue()
+        }
     }
     
     // For debug only


import Foundation

public class SingleServer: Server {

    public var maxConnections: UInt64
    public var maxRequests: UInt64

            self.sock.closeSocket()
        }
        
        if self.isThreaded {
            defer {
                self.connectionsQueue.waitUntilAllOperationsAreFinished()
            }
        }
        
        while true {
            do {
                // wait indefinitely
                try self.sock.waitForConnection(nil)
                let conn = try self.sock.acceptConnection()
                let connection = self.connectionType.init(sock: conn, server: self)
                
                if self.isThreaded {
                    self.connectionsQueue.addOperationWithBlock() {
                        connection.loop(false)
                    }
                } else {
                    connection.loop(false)
                }
            } catch {
                print(error)
                break
