Client only saves one callback at a time
See original GitHub issueDescription
When using a Service Client, and sending two request in a row, because the Client saves one callback at a time, only the latest is used when processing the response message from the service. (look at line 63) https://github.com/RobotWebTools/rclnodejs/blob/2e05913fb0e818f0c3a58904764ef752902a9a5e/lib/client.js#L51-L64
- Library Version: latest develop
- ROS Version: galactic
- Platform / OS: Linux Ubuntu 20.04
Steps To Reproduce
Here is a minimal example that reproduces the bug (based on the example/client-example.js
):
'use strict';
const rclnodejs = require('../index.js');
rclnodejs
.init()
.then(() => {
const node = rclnodejs.createNode('client_example_node');
const client = node.createClient(
'example_interfaces/srv/AddTwoInts',
'add_two_ints'
);
// First call
client.waitForService(1000).then((result) => {
const request = {
a: Math.floor(1),
b: Math.floor(2),
};
if (!result) {
console.log('Error: service not available');
// rclnodejs.shutdown();
return;
}
console.log(`Sending: ${typeof request}`, request);
client.sendRequest(request, (response) => {
console.log(`Result1: ${typeof response}`, response);
// rclnodejs.shutdown();
});
});
// Second call
client.waitForService(1000).then((result) => {
const request = {
a: Math.floor(10),
b: Math.floor(20),
};
if (!result) {
console.log('Error: service not available');
// rclnodejs.shutdown();
return;
}
console.log(`Sending: ${typeof request}`, request);
client.sendRequest(request, (response) => {
console.log(`Result2: ${typeof response}`, response);
// rclnodejs.shutdown();
});
});
rclnodejs.spin(node);
setTimeout(() => {
rclnodejs.shutdown();
}, 1000);
})
.catch((e) => {
console.log(`Error: ${e}`);
});
Expected Behavior
The console log output should be:
Sending: object { a: 1, b: 2 }
Sending: object { a: 10, b: 20 }
Result1: object { sum: 3 }
Result2: object { sum: 30 }
Actual Behavior
Result2
is printed twice:
Sending: object { a: 1, b: 2 }
Sending: object { a: 10, b: 20 }
Result2: object { sum: 3 }
Result2: object { sum: 30 }
Issue Analytics
- State:
- Created a year ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
node.js - Callback function gets called only once
I'm writing a ZooKeeper client to monitor a node. The callback function gets called only the first time I change the data of...
Read more >Part 5. Sharing Data Between Callbacks - Dash Plotly
One way to achieve this is by having multiple outputs for one callback: the expensive task can be done once and immediately used...
Read more >Make your Dash App Faster with Clientside Callbacks
We'll learn to use the Dash Clientside callback to speed things up and expand access to app interactivity. View my book - The...
Read more >IRS customer experience exec says callback trial saved ...
IRS customer experience exec says callback trial saved taxpayers 1.7M hours of hold time.
Read more >Preventing duplicate callback requests in Amazon Connect
At the moment there is no disconnect flow for voice calls where either the agent or customer has hung up first, so we...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ejalaa12 Yes, we should handle the response exactly as the rclcpp does, thanks for investigating the C++ implementation. For nodejs, as you said we can keep a sequence <-> callback map in my mind, and what you need is to change the following
https://github.com/RobotWebTools/rclnodejs/blob/b9ac65211cc19bd6c53a7bca6f1a59ab9591d64c/lib/node.js#L207-L214
processResponse()
and letting the client find the proper callback ifsuccess
is true.I haven’t touched the code for a looong time, maybe make some mistake, just for your reference.
Just submit a PR to add your names and contributions into https://github.com/RobotWebTools/rclnodejs/blob/develop/CONTRIBUTORS.md, then I will merge it