File tree Expand file tree Collapse file tree 3 files changed +32
-24
lines changed Expand file tree Collapse file tree 3 files changed +32
-24
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ trait PortfolioSolver extends Solver { self =>
58
58
}
59
59
}
60
60
61
- inox.utils.findFirst(fs)(_._2 != Unknown ) match {
61
+ inox.utils.FutureUtils . findFirst(fs)(_._2 != Unknown ) match {
62
62
case Some ((s, r)) =>
63
63
resultSolver = s.getResultSolver
64
64
resultSolver.foreach { solv =>
Original file line number Diff line number Diff line change
1
+ /* Copyright 2009-2021 EPFL, Lausanne */
2
+
3
+ package inox .utils
4
+
5
+ import scala .util ._
6
+ import scala .concurrent ._
7
+ import scala .concurrent .duration ._
8
+ import scala .concurrent .ExecutionContext .Implicits .global
9
+ import java .util .concurrent .atomic .AtomicInteger
10
+
11
+ object FutureUtils {
12
+
13
+ def findFirst [T ](futures : Seq [Future [T ]])(cond : T => Boolean ): Option [T ] = {
14
+ val p = Promise [Option [T ]]()
15
+ val n = futures.length
16
+ val i = new AtomicInteger (0 )
17
+
18
+ for (future <- futures) {
19
+ future.onComplete((result : Try [T ]) => result match {
20
+ case Success (res) if cond(res) =>
21
+ p.trySuccess(Some (res))
22
+ case _ =>
23
+ synchronized { i.getAndIncrement() }
24
+ if (i.get == n) p.trySuccess(None )
25
+ })
26
+ }
27
+ Await .result(p.future, Duration .Inf )
28
+ }
29
+
30
+ }
Original file line number Diff line number Diff line change 2
2
3
3
package inox
4
4
5
- import scala .util ._
6
- import scala .concurrent ._
7
- import scala .concurrent .duration ._
8
- import scala .concurrent .ExecutionContext .Implicits .global
9
-
10
5
/** Various utilities used throughout the Inox system */
11
6
package object utils {
12
7
@@ -31,22 +26,5 @@ package object utils {
31
26
}
32
27
v2
33
28
}
34
-
35
- def findFirst [T ](futures : Seq [Future [T ]])(cond : T => Boolean ): Option [T ] = {
36
- val p = Promise [Option [T ]]()
37
- val n = futures.length
38
- var i = 0
39
-
40
- for (future <- futures) {
41
- future.onComplete((result : Try [T ]) => result match {
42
- case Success (res) if cond(res) =>
43
- p.trySuccess(Some (res))
44
- case _ =>
45
- synchronized { i += 1 }
46
- if (i == n) p.trySuccess(None )
47
- })
48
- }
49
- Await .result(p.future, Duration .Inf )
50
- }
51
-
29
+
52
30
}
You can’t perform that action at this time.
0 commit comments