Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit dae5dae

Browse files
Jeremias TrautmannMinggang Wang
authored andcommitted
Add support for delay_between_messages CLI argument
1 parent 74fb96b commit dae5dae

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,26 @@ function createServer(options) {
5858
return rclnodejs.init()
5959
.then(() => {
6060
node = rclnodejs.createNode('ros2_web_bridge');
61-
rclnodejs.spin(node);
6261
debug('ROS2 node started');
62+
let timeout = options.delay_between_messages;
63+
if (timeout == undefined) {
64+
timeout = 0;
65+
}
6366
createConnection(options);
67+
spin(node, timeout);
6468
})
6569
.catch(error => shutDown(error));
6670
}
6771

72+
function spin(node, timeout) {
73+
if (rclnodejs.isShutdown()) {
74+
shutDown();
75+
return;
76+
}
77+
node.spinOnce();
78+
setTimeout(spin, timeout, node, timeout);
79+
}
80+
6881
function createConnection(options) {
6982
if (options.address != null) {
7083
debug('Starting in client mode; connecting to ' + options.address);

0 commit comments

Comments
 (0)