Skip to content

Commit

Permalink
Fix issues in Connection Pool (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Dunn authored and djones6 committed Apr 17, 2018
1 parent 877ff1f commit c6c3c25
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Sources/SwiftKuery/ConnectionPool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,15 @@ public class ConnectionPool {
}
item = pool[0]
pool.removeFirst()
// Check if the item is alive, and append a new one to the pool if it isn't
// Check if the item is alive, and replace with a new one if it isn't
if item.isConnected == false {
releaser(item)
capacity -= 1
if let newItem = generator() {
if let replacementItem = generator() {
capacity += 1
pool.append(newItem)
semaphore.signal()
item = replacementItem
} else {
item = nil
}
}
// If we took the last item, we can choose to grow the pool
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftKuery/ConnectionPoolConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class ConnectionPoolConnection: Connection {

/// An indication whether there is a connection to the database.
public var isConnected: Bool {
return connection != nil
return connection?.isConnected ?? false
}

/// Execute a query.
Expand Down

0 comments on commit c6c3c25

Please sign in to comment.