File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
db-async-common/src/main/scala/com/github/mauricio/async/db/pool Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change 16
16
17
17
package com .github .mauricio .async .db .pool
18
18
19
- import scala .concurrent .Future
19
+ import scala .concurrent .{ ExecutionContext , Future }
20
20
21
21
/**
22
22
*
@@ -70,10 +70,12 @@ trait AsyncObjectPool[T] {
70
70
* @return f wrapped with take and giveBack
71
71
*/
72
72
73
- def use [A ](f : T => Future [A ])(implicit executionContext : scala.concurrent. ExecutionContext ) : Future [A ] =
73
+ def use [A ](f : ( T ) => Future [A ])(implicit executionContext : ExecutionContext ): Future [A ] =
74
74
take.flatMap { item =>
75
- f(item).andThen { case _ =>
76
- giveBack(item)
75
+ f(item) recoverWith {
76
+ case error => giveBack(item).flatMap(_ => Future .failed(error))
77
+ } flatMap { res =>
78
+ giveBack(item).map { _ => res }
77
79
}
78
80
}
79
81
You can’t perform that action at this time.
0 commit comments