File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
db-async-common/src/main/scala/com/github/mauricio/async/db/pool Expand file tree Collapse file tree 1 file changed +7
-5
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 .{ExecutionContext , Future }
19
+ import scala .concurrent .{ExecutionContext , Future , Promise }
20
20
21
21
/**
22
22
*
@@ -72,11 +72,13 @@ trait AsyncObjectPool[T] {
72
72
73
73
def use [A ](f : (T ) => Future [A ])(implicit executionContext : ExecutionContext ): Future [A ] =
74
74
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
+ }
79
80
}
81
+ p.future
80
82
}
81
83
82
84
}
You can’t perform that action at this time.
0 commit comments