Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: node.createService with async callback #945

Merged

Conversation

ldegen
Copy link
Contributor

@ldegen ldegen commented Nov 30, 2023

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

  • 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
 

Maybe something wrong with the linter config?

Copy link
Member

@minggangw minggangw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ldegen Thanks for the PR, the fix makes sense, lgtm.

Per what you mentioned in the commit log, I prefer moving the test into a separate file before merging it, for example, test-service-with-async-callback, to make it clear.

@ldegen
Copy link
Contributor Author

ldegen commented Dec 1, 2023

test-service-with-async-callback

Sure, I'll see to it.

@ldegen
Copy link
Contributor Author

ldegen commented Dec 1, 2023

test-service-with-async-callback

Sure, I'll see to it.

Done (92877d2)

@minggangw minggangw merged commit ad93bb0 into RobotWebTools:develop Dec 6, 2023
@minggangw
Copy link
Member

@ldegen thanks for your PR, merged!

minggangw pushed a commit that referenced this pull request Dec 7, 2023
* fix: node.createService with async callback

Related-to: #944
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node.createService does not work with async callback
2 participants