From 395973276587e8b00d06ef0c4d9ca276a700a332 Mon Sep 17 00:00:00 2001 From: Vaci Koblizek Date: Wed, 30 Sep 2020 17:23:15 +0100 Subject: [PATCH] handle resolve --- .../src/main/java/org/capnproto/RpcState.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/runtime/src/main/java/org/capnproto/RpcState.java b/runtime/src/main/java/org/capnproto/RpcState.java index 0742d19..f11df61 100644 --- a/runtime/src/main/java/org/capnproto/RpcState.java +++ b/runtime/src/main/java/org/capnproto/RpcState.java @@ -448,6 +448,41 @@ final class RpcState { } void handleResolve(IncomingRpcMessage message, RpcProtocol.Resolve.Reader resolve) { + + ClientHook replacement = null; + Throwable exc = null; + + switch (resolve.which()) { + case CAP: + replacement = receiveCap(resolve.getCap(), message.getAttachedFds()); + break; + case EXCEPTION: + exc = new RuntimeException(resolve.getException().getReason().toString()); + break; + default: + assert false; + return; + } + + var imp = imports.find(resolve.getPromiseId()); + if (imp == null) { + return; + } + + var fulfiller = imp.promise; + if (fulfiller != null) { + if (exc != null) { + fulfiller.completeExceptionally(exc); + } + else { + fulfiller.complete(replacement); + } + } + else if (imp.importClient != null) { + // It appears this is a valid entry on the import table, but was not expected to be a + // promise. + assert false; + } } void handleDisembargo(RpcProtocol.Disembargo.Reader disembargo) {