File tree Expand file tree Collapse file tree 3 files changed +47
-2
lines changed Expand file tree Collapse file tree 3 files changed +47
-2
lines changed Original file line number Diff line number Diff line change 13
13
14
14
import java .io .Serializable ;
15
15
import java .util .List ;
16
+ import java .util .concurrent .Callable ;
16
17
17
18
import apgas .impl .SerializableRunnable ;
18
19
@@ -31,7 +32,7 @@ private Constructs() {
31
32
* Runs {@code f} then waits for all tasks transitively spawned by {@code f}
32
33
* to complete.
33
34
* <p>
34
- * If {@code f} or the transitively tasks spawned by {@code f} have uncaught
35
+ * If {@code f} or the tasks transitively spawned by {@code f} have uncaught
35
36
* exceptions then {@code finish(f)} then throws a {@link MultipleException}
36
37
* that collects these uncaught exceptions.
37
38
*
@@ -44,6 +45,24 @@ public static void finish(Job f) {
44
45
GlobalRuntime .getRuntime ().finish (f );
45
46
}
46
47
48
+ /**
49
+ * Evaluates {@code f}, waits for all the tasks transitively spawned by
50
+ * {@code f}, and returns the result.
51
+ * <p>
52
+ * If {@code f} or the tasks transitively spawned by {@code f} have uncaught
53
+ * exceptions then {@code finish(F)} then throws a {@link MultipleException}
54
+ * that collects these uncaught exceptions.
55
+ *
56
+ * @param <T>
57
+ * the type of the result
58
+ * @param f
59
+ * the function to run
60
+ * @return the result of the evaluation
61
+ */
62
+ public static <T > T finish (Callable <T > f ) {
63
+ return GlobalRuntime .getRuntime ().finish (f );
64
+ }
65
+
47
66
/**
48
67
* Submits a new local task to the global runtime with body {@code f} and
49
68
* returns immediately.
Original file line number Diff line number Diff line change 13
13
14
14
import java .io .Serializable ;
15
15
import java .util .List ;
16
+ import java .util .concurrent .Callable ;
16
17
import java .util .concurrent .ExecutorService ;
17
18
import java .util .function .Consumer ;
18
19
@@ -98,7 +99,7 @@ public static GlobalRuntime getRuntime() {
98
99
* Runs {@code f} then waits for all tasks transitively spawned by {@code f}
99
100
* to complete.
100
101
* <p>
101
- * If {@code f} or the transitively tasks spawned by {@code f} have uncaught
102
+ * If {@code f} or the tasks transitively spawned by {@code f} have uncaught
102
103
* exceptions then {@code finish(F)} then throws a {@link MultipleException}
103
104
* that collects these uncaught exceptions.
104
105
*
@@ -109,6 +110,22 @@ public static GlobalRuntime getRuntime() {
109
110
*/
110
111
protected abstract void finish (Job f );
111
112
113
+ /**
114
+ * Evaluates {@code f}, waits for all the tasks transitively spawned by
115
+ * {@code f}, and returns the result.
116
+ * <p>
117
+ * If {@code f} or the tasks transitively spawned by {@code f} have uncaught
118
+ * exceptions then {@code finish(F)} then throws a {@link MultipleException}
119
+ * that collects these uncaught exceptions.
120
+ *
121
+ * @param <T>
122
+ * the type of the result
123
+ * @param f
124
+ * the function to run
125
+ * @return the result of the evaluation
126
+ */
127
+ protected abstract <T > T finish (Callable <T > f );
128
+
112
129
/**
113
130
* Submits a new local task to the global runtime with body {@code f} and
114
131
* returns immediately.
Original file line number Diff line number Diff line change 20
20
import java .util .List ;
21
21
import java .util .SortedSet ;
22
22
import java .util .TreeSet ;
23
+ import java .util .concurrent .Callable ;
23
24
import java .util .concurrent .ExecutorService ;
24
25
import java .util .concurrent .ForkJoinPool ;
25
26
import java .util .concurrent .ForkJoinTask ;
34
35
import apgas .Place ;
35
36
import apgas .SerializableCallable ;
36
37
import apgas .SerializableJob ;
38
+ import apgas .util .Cell ;
37
39
import apgas .util .GlobalID ;
38
40
39
41
import com .hazelcast .core .IMap ;
@@ -366,6 +368,13 @@ public void finish(Job f) {
366
368
}
367
369
}
368
370
371
+ @ Override
372
+ public <T > T finish (Callable <T > f ) {
373
+ final Cell <T > cell = new Cell <T >();
374
+ finish (() -> cell .set (f .call ()));
375
+ return cell .get ();
376
+ }
377
+
369
378
@ Override
370
379
public void async (Job f ) {
371
380
final Worker worker = currentWorker ();
You can’t perform that action at this time.
0 commit comments