Permalink
Browse files

CachingPool: release unavailable services in make()

  • Loading branch information...
1 parent 22a03ef commit 1fc8ad712cbd8ee6c428bc31cf72e7bd4e62067f @mariusae mariusae committed Mar 18, 2011
Showing with 7 additions and 2 deletions.
  1. +7 −2 finagle-core/src/main/scala/com/twitter/finagle/pool/CachingPool.scala
@@ -31,7 +31,7 @@ class CachingPool[Req, Rep](
deathRow += ((Time.now, underlying))
if (!isScheduled) {
isScheduled = true
- timer.schedule(timeout.fromNow)(collect)
+ timer.schedule(timeout.fromNow) { collect() }
}
} else {
underlying.release()
@@ -47,7 +47,10 @@ class CachingPool[Req, Rep](
timestamp.until(now) >= timeout
}
- dequeued foreach { case (_, service) => service.release() }
+ dequeued foreach { case (_, service) =>
+ service.release()
+ }
+
if (!deathRow.isEmpty) {
// TODO: what happens if an event is scheduled in the past?
timer.schedule(deathRow.head._1 + timeout)(collect)
@@ -64,6 +67,8 @@ class CachingPool[Req, Rep](
val (_, service) = deathRow.dequeue()
if (service.isAvailable)
return Future.value(new WrappedService(service))
+ else
+ service.release()
}
factory.make() map { new WrappedService(_) }

0 comments on commit 1fc8ad7

Please sign in to comment.