From 449a6c51dadde3dcb12c7944ad83dd50ca87caeb Mon Sep 17 00:00:00 2001 From: "philipp.buluschek" Date: Fri, 10 Dec 2021 22:43:01 +0100 Subject: [PATCH 1/5] Added Promise.then method for handling cases where the value is Void (notably in allOf), as this was breaking GWT) --- .../util/concurrent/CompletableFuture.java | 2 +- .../concurrent/impl/NativePromiseImpl.java | 22 +++++++++++++------ .../java/util/concurrent/impl/Promise.java | 3 +++ .../util/concurrent/impl/PromiseImpl.java | 9 +++++++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/CompletableFuture.java b/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/CompletableFuture.java index 77d63a8..5806969 100644 --- a/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/CompletableFuture.java +++ b/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/CompletableFuture.java @@ -91,7 +91,7 @@ public static CompletableFuture allOf(CompletableFuture... futures) { } CompletableFuture future = new CompletableFuture<>(); - and(futures).then((value, reason) -> { + and(futures).then((reason) -> { if (reason != null) { future.tryCompleteThrowable(reason); } else { diff --git a/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/NativePromiseImpl.java b/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/NativePromiseImpl.java index 439fc4b..14fa3c0 100644 --- a/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/NativePromiseImpl.java +++ b/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/NativePromiseImpl.java @@ -16,24 +16,25 @@ package java.util.concurrent.impl; import java.util.function.BiConsumer; +import java.util.function.Consumer; /** * */ -final class NativePromiseImpl implements Promise { +final class NativePromiseImpl implements java.util.concurrent.impl.Promise { - final JsPromise jsPromise; - private JsPromise.Resolver resolver; - private JsPromise.Rejector rejector; + final java.util.concurrent.impl.JsPromise jsPromise; + private java.util.concurrent.impl.JsPromise.Resolver resolver; + private java.util.concurrent.impl.JsPromise.Rejector rejector; NativePromiseImpl() { - jsPromise = new JsPromise((resolve, reject) -> { + jsPromise = new java.util.concurrent.impl.JsPromise((resolve, reject) -> { resolver = resolve; rejector = reject; }); } - NativePromiseImpl(JsPromise promise) { + NativePromiseImpl(java.util.concurrent.impl.JsPromise promise) { assert promise != null; this.jsPromise = promise; } @@ -61,7 +62,14 @@ public void then(BiConsumer callback) { @Override public void then(Runnable callback) { assert callback != null; - JsPromise.OnSettledCallback func = value -> callback.run(); + java.util.concurrent.impl.JsPromise.OnSettledCallback func = value -> callback.run(); jsPromise.then(func, func); } + + public void then(final Consumer callback) { + assert callback != null; + jsPromise.then( + value -> callback.accept(null), + reason -> callback.accept((Throwable) reason)); + } } diff --git a/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/Promise.java b/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/Promise.java index c324696..63a4d84 100644 --- a/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/Promise.java +++ b/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/Promise.java @@ -16,6 +16,7 @@ package java.util.concurrent.impl; import java.util.function.BiConsumer; +import java.util.function.Consumer; /** * @@ -29,4 +30,6 @@ public interface Promise { void then(BiConsumer callback); void then(Runnable callback); + + void then(Consumer callback); } diff --git a/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/PromiseImpl.java b/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/PromiseImpl.java index e729f9a..e328b57 100644 --- a/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/PromiseImpl.java +++ b/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/PromiseImpl.java @@ -22,11 +22,12 @@ import java.util.ArrayList; import java.util.List; import java.util.function.BiConsumer; +import java.util.function.Consumer; /** * */ -final class PromiseImpl implements Promise { +final class PromiseImpl implements java.util.concurrent.impl.Promise { private V value; private Throwable reason; private boolean done; @@ -58,6 +59,12 @@ public void then(Runnable callback) { } } + @Override + public void then(Consumer callback) { + assert callback != null; + then(() -> callback.accept(reason)); + } + private void complete(V value, Throwable reason) { if (!done) { this.value = value; From 425851f2aa2205db1c05a04cba98785e4e88e9c2 Mon Sep 17 00:00:00 2001 From: "philipp.buluschek" Date: Fri, 10 Dec 2021 22:56:10 +0100 Subject: [PATCH 2/5] Clean-up unnecessary IDE reformatting --- .idea/.gitignore | 3 +++ .idea/compiler.xml | 16 +++++++++++++++ .idea/jarRepositories.xml | 20 +++++++++++++++++++ .idea/misc.xml | 11 ++++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ gwt-completablefuture.iml | 13 ++++++++++++ .../concurrent/impl/NativePromiseImpl.java | 14 ++++++------- 8 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 gwt-completablefuture.iml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..6d427fa --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..25daa30 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a1a3117 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/gwt-completablefuture.iml b/gwt-completablefuture.iml new file mode 100644 index 0000000..a2748a6 --- /dev/null +++ b/gwt-completablefuture.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/NativePromiseImpl.java b/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/NativePromiseImpl.java index 14fa3c0..b0ce098 100644 --- a/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/NativePromiseImpl.java +++ b/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/NativePromiseImpl.java @@ -21,20 +21,20 @@ /** * */ -final class NativePromiseImpl implements java.util.concurrent.impl.Promise { +final class NativePromiseImpl implements Promise { - final java.util.concurrent.impl.JsPromise jsPromise; - private java.util.concurrent.impl.JsPromise.Resolver resolver; - private java.util.concurrent.impl.JsPromise.Rejector rejector; + final JsPromise jsPromise; + private JsPromise.Resolver resolver; + private JsPromise.Rejector rejector; NativePromiseImpl() { - jsPromise = new java.util.concurrent.impl.JsPromise((resolve, reject) -> { + jsPromise = new JsPromise((resolve, reject) -> { resolver = resolve; rejector = reject; }); } - NativePromiseImpl(java.util.concurrent.impl.JsPromise promise) { + NativePromiseImpl(JsPromise promise) { assert promise != null; this.jsPromise = promise; } @@ -62,7 +62,7 @@ public void then(BiConsumer callback) { @Override public void then(Runnable callback) { assert callback != null; - java.util.concurrent.impl.JsPromise.OnSettledCallback func = value -> callback.run(); + JsPromise.OnSettledCallback func = value -> callback.run(); jsPromise.then(func, func); } From 75c4aa432b0513bee8cc2ae02fa93dbb386a84e0 Mon Sep 17 00:00:00 2001 From: "philipp.buluschek" Date: Fri, 10 Dec 2021 22:59:18 +0100 Subject: [PATCH 3/5] More IDE clean-up --- .idea/.gitignore | 3 --- .idea/compiler.xml | 16 ---------------- .idea/jarRepositories.xml | 20 -------------------- .idea/misc.xml | 11 ----------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 6 files changed, 64 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/jarRepositories.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 6d427fa..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 712ab9d..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 25daa30..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index a1a3117..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 6c966593b141a0f38c55360c33826749ab992ce3 Mon Sep 17 00:00:00 2001 From: "philipp.buluschek" Date: Fri, 10 Dec 2021 23:00:15 +0100 Subject: [PATCH 4/5] More IDE clean-up --- gwt-completablefuture.iml | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 gwt-completablefuture.iml diff --git a/gwt-completablefuture.iml b/gwt-completablefuture.iml deleted file mode 100644 index a2748a6..0000000 --- a/gwt-completablefuture.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file From 792b08dbfb70e89b077de5f673eeb665f8c0fc9b Mon Sep 17 00:00:00 2001 From: "philipp.buluschek" Date: Fri, 10 Dec 2021 23:03:31 +0100 Subject: [PATCH 5/5] Cleanup --- .../gwt/emul/java/util/concurrent/impl/PromiseImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/PromiseImpl.java b/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/PromiseImpl.java index e328b57..0dfe26d 100644 --- a/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/PromiseImpl.java +++ b/src/main/java/com/ekotrope/gwt/emul/java/util/concurrent/impl/PromiseImpl.java @@ -27,7 +27,7 @@ /** * */ -final class PromiseImpl implements java.util.concurrent.impl.Promise { +final class PromiseImpl implements Promise { private V value; private Throwable reason; private boolean done;