Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions rcljava/src/main/java/org/ros2/rcljava/RCLJava.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,61 @@ public static void spin(final ComposableNode composableNode) {
getGlobalExecutor().removeNode(composableNode);
}

public static void spinOnce(final Node node) {
/**
* Execute one callback for a @{link Node}.
*
* Wait until a callback becomes ready and then execute it.
*
* @param node The node to spin on.
* @param timeout The time to wait for a callback to become ready in nanoseconds.
* If a timeout occurs, then nothing happens and this method returns.
*/
public static void spinOnce(final Node node, long timeout) {
ComposableNode composableNode = new ComposableNode() {
public Node getNode() {
return node;
}
};
getGlobalExecutor().addNode(composableNode);
getGlobalExecutor().spinOnce();
getGlobalExecutor().spinOnce(timeout);
getGlobalExecutor().removeNode(composableNode);
}

public static void spinOnce(final ComposableNode composableNode) {
/**
* Execute one callback for a @{link Node}.
*
* Wait until a callback becomes ready and then execute it.
*
* @param node The node to spin on.
*/
public static void spinOnce(final Node node) {
RCLJava.spinOnce(node, -1);
}

/**
* Execute one callback for a @{link ComposableNode}.
*
* Wait until a callback becomes ready and then execute it.
*
* @param composableNode The composable node to spin on.
* @param timeout The time to wait for a callback to become ready in nanoseconds.
* If a timeout occurs, then nothing happens and this method returns.
*/
public static void spinOnce(final ComposableNode composableNode, long timeout) {
getGlobalExecutor().addNode(composableNode);
getGlobalExecutor().spinOnce();
getGlobalExecutor().spinOnce(timeout);
getGlobalExecutor().removeNode(composableNode);
}
/**
* Execute one callback for a @{link ComposableNode}.
*
* Wait until a callback becomes ready and then execute it.
*
* @param composableNode The composable node to spin on.
*/
public static void spinOnce(final ComposableNode composableNode) {
RCLJava.spinOnce(composableNode, -1);
}

public static void spinSome(final Node node) {
ComposableNode composableNode = new ComposableNode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public final V get(final long timeout, final TimeUnit unit)

while (RCLJava.ok()) {
if (executor != null) {
executor.spinOnce();
executor.spinOnce(timeoutNS);
} else {
Node node = nodeReference.get();
if (node == null) {
return null; // TODO(esteve) do something
}
RCLJava.spinOnce(node);
RCLJava.spinOnce(node, timeoutNS);
}

if (isDone()) {
Expand Down