RobotWebTools / rclnodejs

Node.js version of ROS 2.0 client
https://docs.ros.org/en/humble/Concepts/Basic/About-Client-Libraries.html?highlight=rclnodejs#community-maintained
Apache License 2.0
311 stars 70 forks source link

fix: node.createService with async callback #945

Closed ldegen closed 7 months ago

ldegen commented 7 months ago

This should fix #944

Public API Changes This patch should enable createService to correctly deal with async callback functions. All previously supported "modes" should still work as before.

Description

The only thing that changes is that we now wrap any value returned by the callback in a Promise.resolve(...). We wait for this to resolve before continuing. For a callback that returns a response synchronously, this should resolve right away (next tick, probably, depending on the implementation of Promise), so there should not be any noticable difference for those cases. If the callback returns nothing (or undefined), the same logic as before will prevent us from trying to send the response twice. Only it now also works correctly if the return value is a Promise.

Notes

ldegen commented 7 months ago

test-service-with-async-callback

Sure, I'll see to it.

ldegen commented 7 months ago

test-service-with-async-callback

Sure, I'll see to it.

Done (92877d2)

minggangw commented 7 months ago

@ldegen thanks for your PR, merged!