Skip to content

Instantly share code, notes, and snippets.

@derekjw
Created January 17, 2012 23:46
Show Gist options
  • Save derekjw/1629826 to your computer and use it in GitHub Desktop.
Save derekjw/1629826 to your computer and use it in GitHub Desktop.
akkaDoodlesFoldJava.diff
diff --git a/src/main/java/com/micronautics/akka/dispatch/future/FoldJava.java b/src/main/java/com/micronautics/akka/dispatch/future/FoldJava.java
index 71c51bc..a7aa00f 100755
--- a/src/main/java/com/micronautics/akka/dispatch/future/FoldJava.java
+++ b/src/main/java/com/micronautics/akka/dispatch/future/FoldJava.java
@@ -23,7 +23,7 @@ import java.util.ArrayList;
* Non-blocking fold is executed on the thread of the last Future to be completed.
* If this Future is completed with an exception then the new Future will also contain this exception.
* @see https://github.com/jboner/akka/blob/releasing-2.0-M2/akka-docs/java/code/akka/docs/future/FutureDocTestBase.java */
-class FoldJava {
+public class FoldJava {
/** executorService creates daemon threads, which shut down when the application exits. */
private final ExecutorService executorService = DaemonExecutors.newFixedThreadPool(10);
@@ -48,11 +48,11 @@ class FoldJava {
void blocking() {
- Function2<String, String, ArrayList<String>> function2 = new Function2<String, String, ArrayList<String>>() {
- public ArrayList<String> apply(String url, String contents) {
+ Function2<ArrayList<String>, String, ArrayList<String>> function2 = new Function2<ArrayList<String>, String, ArrayList<String>>() {
+ public ArrayList<String> apply(ArrayList<String> results, String contents) {
if (contents.indexOf("Simpler Concurrency")>0)
- result.add(url);
- return result;
+ results.add(contents);
+ return results;
}
};
Future<ArrayList<String>> resultFuture = Futures.fold(result, futures, function2, context);
@@ -79,6 +79,6 @@ class FoldJava {
public static void main(String[] args) {
FoldJava example = new FoldJava();
example.blocking();
- example.nonBlocking();
+ // example.nonBlocking();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment