From 4f86107c85e80205f8b2492c771abd4168d05b89 Mon Sep 17 00:00:00 2001 From: legendecas Date: Mon, 6 Nov 2023 16:48:17 +0800 Subject: [PATCH] doc: fix embed paths --- .github/dependabot.yml | 106 +++++++++--------- .../node-addon-api/README.md | 4 +- website/README.md | 16 +-- website/docs/build-tools/cmake-js.md | 8 +- website/docs/getting-started/first.md | 20 ++-- website/docs/getting-started/objectwrap.md | 24 ++-- website/docs/special-topics/asyncworker.md | 16 +-- .../special-topics/object-function-refs.md | 16 +-- .../special-topics/thread-safe-functions.md | 12 +- 9 files changed, 111 insertions(+), 111 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6755762e..175af335 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,267 +6,267 @@ updates: interval: daily - package-ecosystem: npm - directory: /1_hello_world/nan + directory: / schedule: interval: daily - package-ecosystem: npm - directory: /1_hello_world/napi + directory: /src/1-getting-started/1_hello_world/nan schedule: interval: daily - package-ecosystem: npm - directory: /1_hello_world/node-addon-api-addon-class + directory: /src/1-getting-started/1_hello_world/napi schedule: interval: daily - package-ecosystem: npm - directory: /1_hello_world/node-addon-api + directory: /src/1-getting-started/1_hello_world/node-addon-api-addon-class schedule: interval: daily - package-ecosystem: npm - directory: /2_function_arguments/nan + directory: /src/1-getting-started/1_hello_world/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /2_function_arguments/napi + directory: /src/1-getting-started/2_function_arguments/nan schedule: interval: daily - package-ecosystem: npm - directory: /2_function_arguments/node-addon-api + directory: /src/1-getting-started/2_function_arguments/napi schedule: interval: daily - package-ecosystem: npm - directory: /3_callbacks/nan + directory: /src/1-getting-started/2_function_arguments/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /3_callbacks/napi + directory: /src/1-getting-started/3_callbacks/nan schedule: interval: daily - package-ecosystem: npm - directory: /3_callbacks/node-addon-api + directory: /src/1-getting-started/3_callbacks/napi schedule: interval: daily - package-ecosystem: npm - directory: /4_object_factory/nan + directory: /src/1-getting-started/3_callbacks/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /4_object_factory/napi + directory: /src/1-getting-started/4_object_factory/nan schedule: interval: daily - package-ecosystem: npm - directory: /4_object_factory/node-addon-api + directory: /src/1-getting-started/4_object_factory/napi schedule: interval: daily - package-ecosystem: npm - directory: /5_function_factory/nan + directory: /src/1-getting-started/4_object_factory/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /5_function_factory/napi + directory: /src/1-getting-started/5_function_factory/nan schedule: interval: daily - package-ecosystem: npm - directory: /5_function_factory/node-addon-api + directory: /src/1-getting-started/5_function_factory/napi schedule: interval: daily - package-ecosystem: npm - directory: /6_object_wrap/nan + directory: /src/1-getting-started/5_function_factory/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /6_object_wrap/napi + directory: /src/1-getting-started/6_object_wrap/nan schedule: interval: daily - package-ecosystem: npm - directory: /6_object_wrap/node-addon-api + directory: /src/1-getting-started/6_object_wrap/napi schedule: interval: daily - package-ecosystem: npm - directory: /7_factory_wrap/nan + directory: /src/1-getting-started/6_object_wrap/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /7_factory_wrap/napi + directory: /src/1-getting-started/7_factory_wrap/nan schedule: interval: daily - package-ecosystem: npm - directory: /7_factory_wrap/node-addon-api + directory: /src/1-getting-started/7_factory_wrap/napi schedule: interval: daily - package-ecosystem: npm - directory: /8_passing_wrapped/nan + directory: /src/1-getting-started/7_factory_wrap/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /8_passing_wrapped/napi + directory: /src/1-getting-started/a-first-project/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /8_passing_wrapped/node-addon-api + directory: /src/2-js-to-native-conversion/8_passing_wrapped/nan schedule: interval: daily - package-ecosystem: npm - directory: /a-first-project/node-addon-api + directory: /src/2-js-to-native-conversion/8_passing_wrapped/napi schedule: interval: daily - package-ecosystem: npm - directory: /array_buffer_to_native/node-addon-api + directory: /src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /async-iterator/node-addon-api + directory: /src/2-js-to-native-conversion/array_buffer_to_native/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /async_pi_estimate/nan + directory: /src/5-async-work/async-iterator/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /async_pi_estimate/node-addon-api + directory: /src/5-async-work/async_pi_estimate/nan schedule: interval: daily - package-ecosystem: npm - directory: /async_work_promise/napi + directory: /src/5-async-work/async_pi_estimate/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /async_work_promise/node-addon-api + directory: /src/5-async-work/async_work_promise/napi schedule: interval: daily - package-ecosystem: npm - directory: /async_work_thread_safe_function/napi + directory: /src/5-async-work/async_work_promise/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /build_with_cmake/napi + directory: /src/5-async-work/async_work_thread_safe_function/napi schedule: interval: daily - package-ecosystem: npm - directory: /build_with_cmake/node-addon-api + directory: /src/8-tooling/build_with_cmake/napi schedule: interval: daily - package-ecosystem: npm - directory: /call-js-from-async-worker-execute/node-addon-api + directory: /src/8-tooling/build_with_cmake/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /emit_event_from_cpp/node-addon-api + directory: /src/5-async-work/call-js-from-async-worker-execute/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /function-reference-demo/node-addon-api + directory: /src/7-events/emit_event_from_cpp/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /inherits_from_event_emitter/node-addon-api + directory: /src/4-references-and-handle-scope/function-reference-demo/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /multiple_load/napi + directory: /src/7-events/inherits_from_event_emitter/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /multiple_load/node_10 + directory: /src/3-context-awareness/napi schedule: interval: daily - package-ecosystem: npm - directory: /napi-asyncworker-example/node-addon-api + directory: /src/3-context-awareness/node_10 schedule: interval: daily - package-ecosystem: npm - directory: /object-template-demo/nan + directory: /src/5-async-work/napi-asyncworker-example/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /object-template-demo/napi + directory: /src/2-js-to-native-conversion/object-template-demo/nan schedule: interval: daily - package-ecosystem: npm - directory: /object-wrap-demo/node-addon-api + directory: /src/2-js-to-native-conversion/object-template-demo/napi schedule: interval: daily - package-ecosystem: npm - directory: / + directory: /src/2-js-to-native-conversion/object-wrap-demo/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /promise-callback-demo/node-addon-api + directory: /src/6-threadsafe-function/promise-callback-demo/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /thread_safe_function_counting/node-addon-api + directory: /src/6-threadsafe-function/thread_safe_function_counting/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /thread_safe_function_round_trip/napi + directory: /src/6-threadsafe-function/thread_safe_function_round_trip/napi schedule: interval: daily - package-ecosystem: npm - directory: /threadsafe-async-iterator/node-addon-api + directory: /src/6-threadsafe-function/threadsafe-async-iterator/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /typed_array_to_native/node-addon-api + directory: /src/2-js-to-native-conversion/typed_array_to_native/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /typed_threadsafe_function/node-addon-api + directory: /src/6-threadsafe-function/typed_threadsafe_function/node-addon-api schedule: interval: daily - package-ecosystem: npm - directory: /typescript_with_addon/node-addon-api + directory: /src/8-tooling/typescript_with_addon/node-addon-api schedule: interval: daily diff --git a/src/8-tooling/typescript_with_addon/node-addon-api/README.md b/src/8-tooling/typescript_with_addon/node-addon-api/README.md index 544dfbac..c5b58212 100644 --- a/src/8-tooling/typescript_with_addon/node-addon-api/README.md +++ b/src/8-tooling/typescript_with_addon/node-addon-api/README.md @@ -3,7 +3,7 @@ ### Build and run: ``` -npm install +npm install npm test ``` @@ -16,4 +16,4 @@ This is a C++ function. This is a C function. ``` -This is using cmake and cmake-js based on the example [build_with_cmake](../build_with_cmake) \ No newline at end of file +This is using cmake and cmake-js based on the example [build_with_cmake](../../build_with_cmake) diff --git a/website/README.md b/website/README.md index b287f8c4..73a41dc8 100644 --- a/website/README.md +++ b/website/README.md @@ -10,11 +10,11 @@ The website is generated by [Gatsby](https://www.gatsbyjs.org) and published to The basic objective of this site is to publish additional useful information concerning the Node-API technology that extends beyond the basic documentation. -Ideally, pages published to this site should reference a working demo module that is also stored in this same repository. Features configured into the Gatsby project make embedding example source code fairly straightforward. +Ideally, pages published to this site should reference a working demo module that is also stored in this same repository. Features configured into the Gatsby project make embedding example source code fairly straightforward. ## Contributing -Submissions are gratefully accepted. Simply fork the [node-addon-examples](https://github.com/nodejs/node-addon-examples) repository containing this directory, make your changes, and submit a PR. +Submissions are gratefully accepted. Simply fork the [node-addon-examples](https://github.com/nodejs/node-addon-examples) repository containing this directory, make your changes, and submit a PR. All of the site's content is located in the `docs` directory. Besides the Markdown files, there is also the `toc.json` file that needs to be updated when pages are added or removed. @@ -29,11 +29,11 @@ Each of the Markdown files includes front matter that Gatsby uses when formattin | `prev` | The `id` of the page to be shown as the Previous link at the bottom of the page. | | `next` | The `id` of the page to be shown as the Next link at the bottom of the page. | -The `prev` and `next` links can be omitted for the first and last pages in the set, respectively. +The `prev` and `next` links can be omitted for the first and last pages in the set, respectively. ### Gatsby Basics -This project assumes that Gatsby is installed globally. +This project assumes that Gatsby is installed globally. ``` npm install -g gatsby-cli @@ -56,17 +56,17 @@ These commands are useful while working on the site: ### Embedding Source Code Samples -For this project, Gatsby is configured to have the ability to copy example source code into the generated web pages. The advantage of this approach is that the web pages can be easily regenerated whenever the source code files change. +For this project, Gatsby is configured to have the ability to copy example source code into the generated web pages. The advantage of this approach is that the web pages can be easily regenerated whenever the source code files change. Here's the pattern to follow for embedding example source code: ``` -[**package.json**](https://github.com/nodejs/node-addon-examples/blob/HEAD/object-wrap-demo/node-addon-api/package.json) +[**package.json**](https://github.com/nodejs/node-addon-examples/blob/HEAD/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/package.json) -`embed:object-wrap-demo/node-addon-api/package.json` +`embed:src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/package.json` ``` > This snippet is taken from `website/docs/getting-started/objectwrap.md` -The path in the `embed` tag is relative to the main `node-addon-examples` directory, not the `website` directory. +The path in the `embed` tag is relative to the main `node-addon-examples` directory, not the `website` directory. diff --git a/website/docs/build-tools/cmake-js.md b/website/docs/build-tools/cmake-js.md index b320b9df..ec476778 100644 --- a/website/docs/build-tools/cmake-js.md +++ b/website/docs/build-tools/cmake-js.md @@ -68,9 +68,9 @@ An alternative is to manually add the development dependency to your `package.js Here is a complete `package.json` file: - [**package.json**](https://github.com/nodejs/node-addon-examples/blob/main/build_with_cmake/node-addon-api/package.json) + [**package.json**](https://github.com/nodejs/node-addon-examples/blob/main/src/8-tooling/build_with_cmake/node-addon-api/package.json) -`embed:build_with_cmake/node-addon-api/package.json` +`embed:src/8-tooling/build_with_cmake/node-addon-api/package.json` ## CMakeLists.txt @@ -129,9 +129,9 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR}) Here is a complete `CMakeLists.txt` file for an Node-API native module built on `node-addon-api`: - [**CMakeLists.txt**](https://github.com/nodejs/node-addon-examples/blob/main/build_with_cmake/node-addon-api/CMakeLists.txt) + [**CMakeLists.txt**](https://github.com/nodejs/node-addon-examples/blob/main/src/8-tooling/build_with_cmake/node-addon-api/CMakeLists.txt) -`embed:build_with_cmake/node-addon-api/CMakeLists.txt` +`embed:src/8-tooling/build_with_cmake/node-addon-api/CMakeLists.txt` ## Resources diff --git a/website/docs/getting-started/first.md b/website/docs/getting-started/first.md index 6a77c17d..a0287f8b 100644 --- a/website/docs/getting-started/first.md +++ b/website/docs/getting-started/first.md @@ -96,9 +96,9 @@ Let's take a look at the essential files. ## package.json -[**package.json**](https://github.com/nodejs/node-addon-examples/blob/main/a-first-project/node-addon-api/package.json) +[**package.json**](https://github.com/nodejs/node-addon-examples/blob/main/src/1-getting-started/a-first-project/node-addon-api/package.json) -`embed:a-first-project/node-addon-api/package.json` +`embed:src/1-getting-started/a-first-project/node-addon-api/package.json` This is a typical `package.json` file as generated by [Yeoman](http://yeoman.io) from the responses we entered earlier to the `yo napi-module` command. There are a couple of entries of interest here. @@ -108,9 +108,9 @@ There is also a `"gypfile": true` entry which informs npm that your package requ ## binding.gyp -[**binding.gyp**](https://github.com/nodejs/node-addon-examples/blob/main/a-first-project/node-addon-api/binding.gyp) +[**binding.gyp**](https://github.com/nodejs/node-addon-examples/blob/main/src/1-getting-started/a-first-project/node-addon-api/binding.gyp) -`embed:a-first-project/node-addon-api/binding.gyp` +`embed:src/1-getting-started/a-first-project/node-addon-api/binding.gyp` One of the challenges of making C/C++ code available to Node is getting the code compiled, linked, and packaged for a variety of operating systems and architectures. Historically, this would require learning the intricacies of a variety of build tools across a number of operating systems. This is the specific issue GYP seeks to address. @@ -122,9 +122,9 @@ The `binding.gyp` file is a GYP file which is thoroughly documented [here](https ## src/hello_world.cc -[**hello_world.cc**](https://github.com/nodejs/node-addon-examples/blob/main/a-first-project/node-addon-api/src/hello_world.cc) +[**hello_world.cc**](https://github.com/nodejs/node-addon-examples/blob/main/src/1-getting-started/a-first-project/node-addon-api/src/hello_world.cc) -`embed:a-first-project/node-addon-api/src/hello_world.cc` +`embed:src/1-getting-started/a-first-project/node-addon-api/src/hello_world.cc` This is perhaps the simplest useful(?) Node-API file you can have. @@ -140,9 +140,9 @@ The `NODE_API_MODULE` macro at the bottom of the C++ file insures that the `Init ## lib/binding.js -[**binding.js**](https://github.com/nodejs/node-addon-examples/blob/main/a-first-project/node-addon-api/lib/binding.js) +[**binding.js**](https://github.com/nodejs/node-addon-examples/blob/main/src/1-getting-started/a-first-project/node-addon-api/lib/binding.js) -`embed:a-first-project/node-addon-api/lib/binding.js` +`embed:src/1-getting-started/a-first-project/node-addon-api/lib/binding.js` This JavaScript file defines a JavaScript class that acts as an intermediary to the C++ binary. @@ -150,9 +150,9 @@ In this case, the sole export of the binding is the `HelloWorld` function. ## test/test_binding.js -[**test_binding.js**](https://github.com/nodejs/node-addon-examples/blob/main/a-first-project/node-addon-api/test/test_binding.js) +[**test_binding.js**](https://github.com/nodejs/node-addon-examples/blob/main/src/1-getting-started/a-first-project/node-addon-api/test/test_binding.js) -`embed:a-first-project/node-addon-api/test/test_binding.js` +`embed:src/1-getting-started/a-first-project/node-addon-api/test/test_binding.js` This code demonstrates how to load and call the `HelloWorld` function using JavaScript. Recall that the sole export from the binding is the `HelloWorld` function. The function is loaded into the `HelloWorld` variable using the `require` command. diff --git a/website/docs/getting-started/objectwrap.md b/website/docs/getting-started/objectwrap.md index 89e04f29..ea37b479 100644 --- a/website/docs/getting-started/objectwrap.md +++ b/website/docs/getting-started/objectwrap.md @@ -99,9 +99,9 @@ Let's take a look at the essential files. ## package.json -[**package.json**](https://github.com/nodejs/node-addon-examples/blob/main/object-wrap-demo/node-addon-api/package.json) +[**package.json**](https://github.com/nodejs/node-addon-examples/blob/main/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/package.json) -`embed:object-wrap-demo/node-addon-api/package.json` +`embed:src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/package.json` This is a typical `package.json` file as generated by [Yeoman](http://yeoman.io) from the responses we entered earlier to the `yo napi-module` command. There are a couple of entries of interest here. @@ -111,9 +111,9 @@ There is also a `"gypfile": true` entry which informs npm that your package requ ## binding.gyp -[**binding.gyp**](https://github.com/nodejs/node-addon-examples/blob/main/object-wrap-demo/node-addon-api/binding.gyp) +[**binding.gyp**](https://github.com/nodejs/node-addon-examples/blob/main/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/binding.gyp) -`embed:object-wrap-demo/node-addon-api/binding.gyp` +`embed:src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/binding.gyp` One of the challenges of making C/C++ code available to Node is getting the code compiled, linked, and packaged for a variety of operating systems and architectures. Historically, this would require learning the intricacies of a variety of build tools across a number of operating systems. This is the specific issue GYP seeks to address. @@ -125,13 +125,13 @@ The `binding.gyp` file is a GYP file which is thoroughly documented [here](https ## src/object\_wrap\_demo.h and src/object\_wrap\_demo.cc -[**object\_wrap\_demo.h**](https://github.com/nodejs/node-addon-examples/blob/main/object-wrap-demo/node-addon-api/src/object_wrap_demo.h) +[**object\_wrap\_demo.h**](https://github.com/nodejs/node-addon-examples/blob/main/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/src/object_wrap_demo.h) -`embed:object-wrap-demo/node-addon-api/src/object_wrap_demo.h` +`embed:src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/src/object_wrap_demo.h` -[**object\_wrap\_demo.cc**](https://github.com/nodejs/node-addon-examples/blob/main/object-wrap-demo/node-addon-api/src/object_wrap_demo.cc) +[**object\_wrap\_demo.cc**](https://github.com/nodejs/node-addon-examples/blob/main/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/src/object_wrap_demo.cc) -`embed:object-wrap-demo/node-addon-api/src/object_wrap_demo.cc` +`embed:src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/src/object_wrap_demo.cc` Here is the nub of our project where all the magic occurs. This is a sample C++ file that shows how to use the power of the `node-addon-api` package to access, create, and manipulate JavaScript objects in C++. @@ -149,9 +149,9 @@ The macro call at the bottom of the C++ file, `NODE_API_MODULE(addon, Init)`, sp ## lib/binding.js -[**binding.js**](https://github.com/nodejs/node-addon-examples/blob/main/object-wrap-demo/node-addon-api/lib/binding.js) +[**binding.js**](https://github.com/nodejs/node-addon-examples/blob/main/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/lib/binding.js) -`embed:object-wrap-demo/node-addon-api/lib/binding.js` +`embed:src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/lib/binding.js` This JavaScript file defines a JavaScript class that acts as an intermediary to the C++ binary. @@ -159,9 +159,9 @@ The file defines a `ObjectWrapDemo` JavaScript class and then exports it. When ` ## test/test_binding.js -[**test_binding.js**](https://github.com/nodejs/node-addon-examples/blob/main/object-wrap-demo/node-addon-api/test/test_binding.js) +[**test_binding.js**](https://github.com/nodejs/node-addon-examples/blob/main/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/test/test_binding.js) -`embed:object-wrap-demo/node-addon-api/test/test_binding.js` +`embed:src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/test/test_binding.js` This code demonstrates how to use the `ObjectWrapDemo` JavaScript class defined in `lib/binding.js`. diff --git a/website/docs/special-topics/asyncworker.md b/website/docs/special-topics/asyncworker.md index af86ba23..71d6618d 100644 --- a/website/docs/special-topics/asyncworker.md +++ b/website/docs/special-topics/asyncworker.md @@ -17,9 +17,9 @@ In this example, we're going to create a `SimpleAsyncWorker` class that subclass Here's the C++ header file for `SimpleAsyncWorker`: -[**SimpleAsyncWorker.h**](https://github.com/nodejs/node-addon-examples/blob/main/napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.h) +[**SimpleAsyncWorker.h**](https://github.com/nodejs/node-addon-examples/blob/main/src/5-async-work/napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.h) -`embed:napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.h` +`embed:src/5-async-work/napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.h` This code declares a constructor that takes as an argument the length of time (in seconds) the `SimpleAsyncWorker` is to run. A private data member is declared to hold this value. @@ -27,9 +27,9 @@ The header also declares two methods, `Execute` and `OnOK`, which override metho And here's the C++ implementation file for `SimpleAsyncWorker`: -[**SimpleAsyncWorker.cc**](https://github.com/nodejs/node-addon-examples/blob/main/napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.cc) +[**SimpleAsyncWorker.cc**](https://github.com/nodejs/node-addon-examples/blob/main/src/5-async-work/napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.cc) -`embed:napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.cc` +`embed:src/5-async-work/napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.cc` The constructor takes two arguments. `callback` is the JavaScript function that gets called when the `Execute` method returns. `callback` gets called whether there was an error or not. The second constructor argument, `runTime`, is an integer value indicating how long (in seconds) the worker is to run. @@ -47,9 +47,9 @@ Note that unlike `Execute`, the `OnOK` and `OnError` methods _do_ have access to We need a C++ function that instantiates `SimpleAsyncWorker` objects and requests them to be queued. This function needs to be registered with Node-API so that it is accessible from the JavaScript code. -[**RunSimpleAsyncWorker.cc**](https://github.com/nodejs/node-addon-examples/blob/main/napi-asyncworker-example/node-addon-api/src/RunSimpleAsyncWorker.cc) +[**RunSimpleAsyncWorker.cc**](https://github.com/nodejs/node-addon-examples/blob/main/src/5-async-work/napi-asyncworker-example/node-addon-api/src/RunSimpleAsyncWorker.cc) -`embed:napi-asyncworker-example/node-addon-api/src/RunSimpleAsyncWorker.cc` +`embed:src/5-async-work/napi-asyncworker-example/node-addon-api/src/RunSimpleAsyncWorker.cc` The `runSimpleAsyncWorker` function, which is accessible from JavaScript, takes two arguments which are passed through the `info` argument. The first argument, which is passed as `info[0]`, is the `runTime` and the second argument is the JavaScript callback function which gets called when the `Execute` method returns. @@ -61,9 +61,9 @@ Once the `SimpleAsyncWorker` object is queued, `runSimpleAsyncWorker` formulates Here's a simple JavaScript program that shows how to run `SimpleAsyncWorker` instances. -[**Test.js**](https://github.com/nodejs/node-addon-examples/blob/main/napi-asyncworker-example/node-addon-api/test/Test.js) +[**Test.js**](https://github.com/nodejs/node-addon-examples/blob/main/src/5-async-work/napi-asyncworker-example/node-addon-api/test/Test.js) -`embed:napi-asyncworker-example/node-addon-api/test/Test.js` +`embed:src/5-async-work/napi-asyncworker-example/node-addon-api/test/Test.js` In this code, the `runSimpleAsyncWorker` function is called three times, each with a different `runTime` parameter. Each call specifies `AsyncWorkerCompletion` as the callback function. diff --git a/website/docs/special-topics/object-function-refs.md b/website/docs/special-topics/object-function-refs.md index f0a3bdf0..2b96a87e 100644 --- a/website/docs/special-topics/object-function-refs.md +++ b/website/docs/special-topics/object-function-refs.md @@ -40,9 +40,9 @@ This example code shows how to use the `FunctionReference` class. ### src/native-addon.h -[**native-addon.h**](https://github.com/nodejs/node-addon-examples/blob/main/function-reference-demo/node-addon-api/src/native-addon.h) +[**native-addon.h**](https://github.com/nodejs/node-addon-examples/blob/main/src/4-references-and-handle-scope/function-reference-demo/src/native-addon.h) -`embed:function-reference-demo/node-addon-api/src/native-addon.h` +`embed:src/4-references-and-handle-scope/function-reference-demo/src/native-addon.h` The `NativeAddon` C++ class has two data members that are populated in the `NativeAddon` constructor: @@ -51,9 +51,9 @@ The `NativeAddon` C++ class has two data members that are populated in the `Nati ### src/native-addon.cc -[**native-addon.cc**](https://github.com/nodejs/node-addon-examples/blob/main/function-reference-demo/node-addon-api/src/native-addon.cc) +[**native-addon.cc**](https://github.com/nodejs/node-addon-examples/blob/main/src/4-references-and-handle-scope/function-reference-demo/src/native-addon.cc) -`embed:function-reference-demo/node-addon-api/src/native-addon.cc` +`embed:src/4-references-and-handle-scope/function-reference-demo/src/native-addon.cc` The `NativeAddon` constructor, which is called from JavaScript, takes two function arguments. The first argument is stored as a `Napi::FunctionReference` and the second is stored as a `Napi::Function`. @@ -65,17 +65,17 @@ The `NativeAddon` class implements two methods which can be called from JavaScri ### src/binding.cc -[**binding.cc**](https://github.com/nodejs/node-addon-examples/blob/main/function-reference-demo/node-addon-api/src/binding.cc) +[**binding.cc**](https://github.com/nodejs/node-addon-examples/blob/main/src/4-references-and-handle-scope/function-reference-demo/src/binding.cc) -`embed:function-reference-demo/node-addon-api/src/binding.cc` +`embed:src/4-references-and-handle-scope/function-reference-demo/src/binding.cc` This is a standard `binding.cc` file: ### index.js -[**index.js**](https://github.com/nodejs/node-addon-examples/blob/main/function-reference-demo/node-addon-api/index.js) +[**index.js**](https://github.com/nodejs/node-addon-examples/blob/main/src/4-references-and-handle-scope/function-reference-demo/index.js) -`embed:function-reference-demo/node-addon-api/index.js` +`embed:src/4-references-and-handle-scope/function-reference-demo/index.js` This JavaScript code shows the use of the `NativeAddon` class. Note that the call to the native `tryCallByStoredFunction` method fails because the data member on which it relies is not valid. diff --git a/website/docs/special-topics/thread-safe-functions.md b/website/docs/special-topics/thread-safe-functions.md index ff9aa4c1..bd044c4e 100644 --- a/website/docs/special-topics/thread-safe-functions.md +++ b/website/docs/special-topics/thread-safe-functions.md @@ -59,21 +59,21 @@ This example node-addon-api module creates exposes a single function that create ### binding.gyp -[**binding.gyp**](https://github.com/nodejs/node-addon-examples/blob/main/thread_safe_function_counting/node-addon-api/binding.gyp) +[**binding.gyp**](https://github.com/nodejs/node-addon-examples/blob/main/src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/binding.gyp) -`embed:thread_safe_function_counting/node-addon-api/binding.gyp` +`embed:src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/binding.gyp` ### addon.cc -[**addon.cc**](https://github.com/nodejs/node-addon-examples/blob/main/thread_safe_function_counting/node-addon-api/addon.cc) +[**addon.cc**](https://github.com/nodejs/node-addon-examples/blob/main/src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/addon.cc) -`embed:thread_safe_function_counting/node-addon-api/addon.cc` +`embed:src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/addon.cc` ### addon.js -[**addon.js**](https://github.com/nodejs/node-addon-examples/blob/main/thread_safe_function_counting/node-addon-api/addon.js) +[**addon.js**](https://github.com/nodejs/node-addon-examples/blob/main/src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/addon.js) -`embed:thread_safe_function_counting/node-addon-api/addon.js` +`embed:src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/addon.js` Running the above script will provide output similar to: