@@ -16,7 +16,6 @@ trait AsyncConnectionPool extends VertxExecutionContext {
16
16
17
17
private var poolSize : Int = 0
18
18
private val availableConnections : Queue [Connection ] = Queue .empty
19
- private val usedConnections : Queue [Connection ] = Queue .empty
20
19
private val waiters : Queue [Promise [Connection ]] = Queue .empty
21
20
22
21
def create (): Future [Connection ]
@@ -44,21 +43,15 @@ trait AsyncConnectionPool extends VertxExecutionContext {
44
43
}
45
44
}
46
45
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()
62
55
}
63
56
64
57
private def notifyWaitersAboutAvailableConnection (): Future [_] = {
@@ -72,7 +65,6 @@ trait AsyncConnectionPool extends VertxExecutionContext {
72
65
}
73
66
74
67
def giveBack (conn : Connection )(implicit ec : ExecutionContext ) = {
75
- usedConnections.dequeueFirst(_ == conn)
76
68
if (conn.isConnected) {
77
69
availableConnections.enqueue(conn)
78
70
} else {
0 commit comments