From 6326f965ab804aebcd5787a33057030e252e5733 Mon Sep 17 00:00:00 2001 From: Vaci Koblizek Date: Thu, 26 Nov 2020 15:17:39 +0000 Subject: [PATCH] new style resolve switch --- .../src/main/java/org/capnproto/RpcState.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/runtime-rpc/src/main/java/org/capnproto/RpcState.java b/runtime-rpc/src/main/java/org/capnproto/RpcState.java index ea8f930..2c62f14 100644 --- a/runtime-rpc/src/main/java/org/capnproto/RpcState.java +++ b/runtime-rpc/src/main/java/org/capnproto/RpcState.java @@ -1561,7 +1561,6 @@ final class RpcState { */ RpcPipeline(QuestionRef questionRef) { this(questionRef, null); - // TODO implement tail calls... } @Override @@ -1569,30 +1568,30 @@ final class RpcState { // TODO avoid conversion to/from ArrayList? var key = new ArrayList<>(Arrays.asList(ops)); - var hook = this.clientMap.computeIfAbsent(key, k -> { - switch (state) { - case WAITING: { + return this.clientMap.computeIfAbsent(key, k -> { + return switch (state) { + case WAITING -> { var pipelineClient = new PipelineClient(this.questionRef, ops); if (this.redirectLater == null) { // This pipeline will never get redirected, so just return the PipelineClient. - return pipelineClient; + yield pipelineClient; } assert this.resolveSelf != null; var resolutionPromise = this.resolveSelf.thenApply( response -> response.getResults().getPipelinedCap(ops)); - return new PromiseClient(pipelineClient, resolutionPromise, null); + yield new PromiseClient(pipelineClient, resolutionPromise, null); } - - case RESOLVED: + case RESOLVED -> { assert this.resolved != null; - return this.resolved.getResults().getPipelinedCap(ops); - - default: - return Capability.newBrokenCap(broken); - } + yield this.resolved.getResults().getPipelinedCap(ops); + } + case BROKEN -> { + assert this.broken != null; + yield Capability.newBrokenCap(broken); + } + }; }); - return hook; } @Override