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
I am not sure if I put my test case in the right spot.
I am getting 153 linter errors for code that I never touched. They all look like this:
/workspaces/pwd/rclnodejs/test/utils.js
0:0 error Parsing error: require() of ES Module /workspaces/pwd/rclnodejs/node_modules/eslint/node_modules/eslint-scope/lib/definition.js from /workspaces/pwd/rclnodejs/node_modules/babel-eslint/lib/require-from-eslint.js not supported.
Instead change the require of definition.js in /workspaces/pwd/rclnodejs/node_modules/babel-eslint/lib/require-from-eslint.js to a dynamic import() which is available in all CommonJS modules
This should fix #944
Public API Changes This patch should enable
createService
to correctly deal withasync
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
I am getting 153 linter errors for code that I never touched. They all look like this:
Maybe something wrong with the linter config?