-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
doc: fix n-api asynchronous threading documentation #19073
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3269,9 +3269,11 @@ napi_status napi_create_async_work(napi_env env, | |
- `[in] async_resource_name`: Identifier for the kind of resource that is | ||
being provided for diagnostic information exposed by the `async_hooks` API. | ||
- `[in] execute`: The native function which should be called to excute | ||
the logic asynchronously. | ||
the logic asynchronously. The given function is called from a worker pool | ||
thread and executes in parallel with the main event loop thread. | ||
- `[in] complete`: The native function which will be called when the | ||
asynchronous logic is comple or is cancelled. | ||
asynchronous logic is completed or is cancelled. The given function is called | ||
from the main event loop thread. | ||
- `[in] data`: User-provided data context. This will be passed back into the | ||
execute and complete functions. | ||
- `[out] result`: `napi_async_work*` which is the handle to the newly created | ||
|
@@ -3346,8 +3348,7 @@ callback invocation, even if it has been successfully cancelled. | |
|
||
## Custom Asynchronous Operations | ||
The simple asynchronous work APIs above may not be appropriate for every | ||
scenario, because with those the async execution still happens on the main | ||
event loop. When using any other async mechanism, the following APIs are | ||
scenario. When using any other async mechanism, the following APIs are | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed; expanded the abbreviations. |
||
necessary to ensure an async operation is properly tracked by the runtime. | ||
|
||
### napi_async_init | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ebickle is it guaranteed to execute in parallel with the main event loop thread? Or is it more precise to say "can execute in parallel with the main event loop thread"? That is, is there a situation where the only thread available to do work in the thread pool is the main event loop thread?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@digitalinfinity agree completely with the suggestion. Regardless of whether or not the
execute
function can ever run in the main event loop thread, it's never guaranteed to be executed in parallel due to the OS' context switching. Updated the documentation.