Skip to content

Commit 5763e70

Browse files
committed
Kicked unnecessary usedConnections queue + version in Readme.md
1 parent cc5a27e commit 5763e70

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This Vert.x module uses the https://github.com/mauricio/postgresql-async drivers
1111

1212
## Installation
1313

14-
`vertx install io.vertx~mod-mysql-postgresql~0.2.0`
14+
`vertx install io.vertx~mod-mysql-postgresql~0.3.0-SNAPSHOT`
1515

1616
## Configuration
1717

src/main/scala/io/vertx/asyncsql/database/pool/AsyncConnectionPool.scala

+9-17
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ trait AsyncConnectionPool extends VertxExecutionContext {
1616

1717
private var poolSize: Int = 0
1818
private val availableConnections: Queue[Connection] = Queue.empty
19-
private val usedConnections: Queue[Connection] = Queue.empty
2019
private val waiters: Queue[Promise[Connection]] = Queue.empty
2120

2221
def create(): Future[Connection]
@@ -44,21 +43,15 @@ trait AsyncConnectionPool extends VertxExecutionContext {
4443
}
4544
}
4645

47-
def take(): Future[Connection] = {
48-
(availableConnections.dequeueFirst(_ => true) match {
49-
case Some(connection) =>
50-
if (connection.isConnected) {
51-
Future.successful(connection)
52-
} else {
53-
poolSize -= 1
54-
createConnection()
55-
}
56-
case None =>
57-
createOrWaitForAvailableConnection()
58-
}) map { c =>
59-
usedConnections.enqueue(c)
60-
c
61-
}
46+
def take(): Future[Connection] = availableConnections.dequeueFirst(_ => true) match {
47+
case Some(connection) =>
48+
if (connection.isConnected) {
49+
Future.successful(connection)
50+
} else {
51+
poolSize -= 1
52+
take()
53+
}
54+
case None => createOrWaitForAvailableConnection()
6255
}
6356

6457
private def notifyWaitersAboutAvailableConnection(): Future[_] = {
@@ -72,7 +65,6 @@ trait AsyncConnectionPool extends VertxExecutionContext {
7265
}
7366

7467
def giveBack(conn: Connection)(implicit ec: ExecutionContext) = {
75-
usedConnections.dequeueFirst(_ == conn)
7668
if (conn.isConnected) {
7769
availableConnections.enqueue(conn)
7870
} else {

0 commit comments

Comments
 (0)