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

n-api: document nextTick timing in callbacks #33804

Closed
wants to merge 1 commit into from

Conversation

mafintosh
Copy link
Member

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Document that nextTicks when c/c++ calls js are ran before returning to c/c++ if any are scheduled by the js callback. Just fixed a bug in Electron related to this, so thought we could help others avoid this quirk by making it more clear.

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. node-api Issues and PRs related to the Node-API. labels Jun 9, 2020
doc/api/n-api.md Outdated Show resolved Hide resolved
@mafintosh mafintosh force-pushed the n-api-next-tick-timing branch from 91b6970 to f457dd0 Compare June 9, 2020 09:20
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina requested review from jasnell and addaleax June 9, 2020 09:21
@mafintosh mafintosh force-pushed the n-api-next-tick-timing branch from f457dd0 to 96d65ba Compare June 9, 2020 09:25
Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

👍 Overall LGTM. Please address the issue that lint complains.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

LGTM with the linter warning addressed – and the linter complaint is correct, this isn’t a side effect of the function but rather half its purpose :)

@mafintosh mafintosh force-pushed the n-api-next-tick-timing branch from 96d65ba to e848bb4 Compare June 11, 2020 11:49
@mafintosh
Copy link
Member Author

mafintosh commented Jun 11, 2020

Updated the message

@@ -4755,6 +4755,9 @@ is sufficient and appropriate. Use of the `napi_make_callback` function
may be required when implementing custom async behavior that does not use
`napi_create_async_work`.

Any `process.nextTick`s or Promises scheduled on the microtask queue by
JavaScript during the callback are ran before returning back to C/C++.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
JavaScript during the callback are ran before returning back to C/C++.
JavaScript during the callback are run before returning back to C/C++.

Copy link
Contributor

Choose a reason for hiding this comment

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

Better perhaps?

Suggested change
JavaScript during the callback are ran before returning back to C/C++.
JavaScript during the callback are executed before returning back to C/C++.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM with fixes suggested by @gabrielschulhof

@nodejs-github-bot
Copy link
Collaborator

mcollina pushed a commit that referenced this pull request Jun 17, 2020
PR-URL: #33804
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gabriel Schulhof <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
@mcollina
Copy link
Member

Landed in 50fb019

@mcollina mcollina closed this Jun 17, 2020
codebytere pushed a commit that referenced this pull request Jun 18, 2020
PR-URL: #33804
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gabriel Schulhof <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
@codebytere codebytere mentioned this pull request Jun 28, 2020
codebytere pushed a commit that referenced this pull request Jun 30, 2020
PR-URL: #33804
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gabriel Schulhof <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
codebytere pushed a commit that referenced this pull request Jul 10, 2020
PR-URL: #33804
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gabriel Schulhof <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
@codebytere codebytere mentioned this pull request Jul 13, 2020
codebytere pushed a commit that referenced this pull request Jul 14, 2020
PR-URL: #33804
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gabriel Schulhof <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants