doc: link n-api module init to multi-load addons

Add a blurb to the documentation of `NAPI_MODULE_INIT()` pointing to
the discussion of the consequences of providing an addon that can be
loaded multiple times from multiple contexts.

PR-URL: https://github.com/nodejs/node/pull/21891
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Gabriel Schulhof 2018-07-19 14:44:35 -04:00
parent 53296e8a3e
commit 5384570486

View File

@ -1183,6 +1183,10 @@ This macro includes `NAPI_MODULE`, and declares an `Init` function with a
special name and with visibility beyond the addon. This will allow Node.js to special name and with visibility beyond the addon. This will allow Node.js to
initialize the module even if it is loaded multiple times. initialize the module even if it is loaded multiple times.
There are a few design considerations when declaring a module that may be loaded
multiple times. The documentation of [context-aware addons][] provides more
details.
The variables `env` and `exports` will be available inside the function body The variables `env` and `exports` will be available inside the function body
following the macro invocation. following the macro invocation.
@ -4581,3 +4585,4 @@ This API may only be called from the main thread.
[`process.release`]: process.html#process_process_release [`process.release`]: process.html#process_process_release
[`init` hooks]: async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource [`init` hooks]: async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource
[async_hooks `type`]: async_hooks.html#async_hooks_type [async_hooks `type`]: async_hooks.html#async_hooks_type
[context-aware addons]: addons.html#addons_context_aware_addons