From 30e589600f2d5b4beac2b6bcd485a009d945c730 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Fri, 7 Feb 2020 15:03:07 -0800 Subject: [PATCH] Wait for service before making request This allows time for discovery to happen so that the request is not lost. Signed-off-by: Jacob Perron --- .../ros2/rcljava/examples/client/AddTwoIntsClient.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rcljava_examples/src/main/java/org/ros2/rcljava/examples/client/AddTwoIntsClient.java b/rcljava_examples/src/main/java/org/ros2/rcljava/examples/client/AddTwoIntsClient.java index 22cff0a..d8357a6 100644 --- a/rcljava_examples/src/main/java/org/ros2/rcljava/examples/client/AddTwoIntsClient.java +++ b/rcljava_examples/src/main/java/org/ros2/rcljava/examples/client/AddTwoIntsClient.java @@ -38,11 +38,13 @@ public static void main(final String[] args) throws InterruptedException, Except request.setA(2); request.setB(3); - Future future = - client.asyncSendRequest(request); + if (client.waitForService()) { + Future future = + client.asyncSendRequest(request); - System.out.println( - "result of " + request.getA() + " + " + request.getB() + " = " + future.get().getSum()); + System.out.println( + "result of " + request.getA() + " + " + request.getB() + " = " + future.get().getSum()); + } RCLJava.shutdown(); }