Skip to content

Commit 16f9f18

Browse files
committed
Ignore errors generated by AsyncObjectPool.giveBack
Possible fix for mauricio#132, untested.
1 parent a6aabd1 commit 16f9f18

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

db-async-common/src/main/scala/com/github/mauricio/async/db/pool/AsyncObjectPool.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.github.mauricio.async.db.pool
1818

19-
import scala.concurrent.{ExecutionContext, Future}
19+
import scala.concurrent.{ExecutionContext, Future, Promise}
2020

2121
/**
2222
*
@@ -72,11 +72,13 @@ trait AsyncObjectPool[T] {
7272

7373
def use[A](f: (T) => Future[A])(implicit executionContext: ExecutionContext): Future[A] =
7474
take.flatMap { item =>
75-
f(item) recoverWith {
76-
case error => giveBack(item).flatMap(_ => Future.failed(error))
77-
} flatMap { res =>
78-
giveBack(item).map { _ => res }
75+
val p = Promise[A]()
76+
f(item).onComplete { r =>
77+
giveBack(item).onComplete { _ =>
78+
p.complete(r)
79+
}
7980
}
81+
p.future
8082
}
8183

8284
}

0 commit comments

Comments
 (0)