@@ -7,8 +7,8 @@ operation.
7
7
8
8
Once created, execution is requested by calling ` Napi::AsyncWorker::Queue ` . When
9
9
a thread is available for execution the ` Napi::AsyncWorker::Execute ` method will
10
- be invoked. Once ` Napi::AsyncWorker::Execute ` completes either
11
- ` Napi::AsyncWorker::OnOK ` or ` Napi::AsyncWorker::OnError ` will be invoked. Once
10
+ be invoked. Once ` Napi::AsyncWorker::Execute ` completes either
11
+ ` Napi::AsyncWorker::OnOK ` or ` Napi::AsyncWorker::OnError ` will be invoked. Once
12
12
the ` Napi::AsyncWorker::OnOK ` or ` Napi::AsyncWorker::OnError ` methods are
13
13
complete the ` Napi::AsyncWorker ` instance is destructed.
14
14
@@ -38,7 +38,7 @@ void Napi::AsyncWorker::Queue();
38
38
### Cancel
39
39
40
40
Cancels queued work if it has not yet been started. If it has already started
41
- executing, it cannot be cancelled. If cancelled successfully neither
41
+ executing, it cannot be cancelled. If cancelled successfully neither
42
42
` OnOK ` nor ` OnError ` will be called.
43
43
44
44
``` cpp
@@ -90,14 +90,14 @@ void Napi::AsyncWorker::SetError(const std::string& error);
90
90
91
91
### Execute
92
92
93
- This method is used to execute some tasks out of the **event loop** on a libuv
93
+ This method is used to execute some tasks outside of the **event loop** on a libuv
94
94
worker thread. Subclasses must implement this method and the method is run on
95
- a thread other than that running the main event loop. As the method is not
95
+ a thread other than that running the main event loop. As the method is not
96
96
running on the main event loop, it must avoid calling any methods from node-addon-api
97
97
or running any code that might invoke JavaScript. Instead, once this method is
98
98
complete any interaction through node-addon-api with JavaScript should be implemented
99
- in the `Napi::AsyncWorker::OnOK` method which runs on the main thread and is
100
- invoked when the `Napi::AsyncWorker::Execute` method completes.
99
+ in the `Napi::AsyncWorker::OnOK` method and `Napi::AsyncWorker::OnError` which run
100
+ on the main thread and are invoked when the `Napi::AsyncWorker::Execute` method completes.
101
101
102
102
```cpp
103
103
virtual void Napi::AsyncWorker::Execute() = 0;
@@ -106,18 +106,19 @@ virtual void Napi::AsyncWorker::Execute() = 0;
106
106
### OnOK
107
107
108
108
This method is invoked when the computation in the ` Execute ` method ends.
109
- The default implementation runs the Callback optionally provided when the AsyncWorker class
110
- was created. The callback will by default receive no arguments. To provide arguments,
111
- override the ` GetResult() ` method.
109
+ The default implementation runs the ` Callback ` optionally provided when the
110
+ ` AsyncWorker ` class was created. The ` Callback ` will by default receive no
111
+ arguments. The arguments to the ` Callback ` can be provided by overriding the
112
+ ` GetResult() ` method.
112
113
113
114
``` cpp
114
115
virtual void Napi::AsyncWorker::OnOK ();
115
116
```
116
117
### GetResult
117
118
118
- This method returns the arguments passed to the Callback invoked by the default
119
+ This method returns the arguments passed to the ` Callback ` invoked by the default
119
120
` OnOK() ` implementation. The default implementation returns an empty vector,
120
- providing no arguments to the Callback.
121
+ providing no arguments to the ` Callback ` .
121
122
122
123
``` cpp
123
124
virtual std::vector<napi_value> Napi::AsyncWorker::GetResult (Napi::Env env);
@@ -128,7 +129,7 @@ virtual std::vector<napi_value> Napi::AsyncWorker::GetResult(Napi::Env env);
128
129
This method is invoked after `Napi::AsyncWorker::Execute` completes if an error
129
130
occurs while `Napi::AsyncWorker::Execute` is running and C++ exceptions are
130
131
enabled or if an error was set through a call to `Napi::AsyncWorker::SetError`.
131
- The default implementation calls the callback provided when the `Napi::AsyncWorker`
132
+ The default implementation calls the `Callback` provided when the `Napi::AsyncWorker`
132
133
class was created, passing in the error as the first parameter.
133
134
134
135
```cpp
@@ -172,7 +173,7 @@ explicit Napi::AsyncWorker(const Napi::Function& callback, const char* resource_
172
173
173
174
- ` [in] callback ` : The function which will be called when an asynchronous
174
175
operations ends. The given function is called from the main event loop thread.
175
- - ` [in] resource_name ` : Null-terminated strings that represents the
176
+ - ` [in] resource_name ` : Null-terminated string that represents the
176
177
identifier for the kind of resource that is being provided for diagnostic
177
178
information exposed by the async_hooks API.
178
179
@@ -189,7 +190,7 @@ explicit Napi::AsyncWorker(const Napi::Function& callback, const char* resource_
189
190
190
191
- `[in] callback`: The function which will be called when an asynchronous
191
192
operations ends. The given function is called from the main event loop thread.
192
- - `[in] resource_name`: Null-terminated strings that represents the
193
+ - `[in] resource_name`: Null-terminated string that represents the
193
194
identifier for the kind of resource that is being provided for diagnostic
194
195
information exposed by the async_hooks API.
195
196
- `[in] resource`: Object associated with the asynchronous operation that
@@ -224,7 +225,7 @@ explicit Napi::AsyncWorker(const Napi::Object& receiver, const Napi::Function& c
224
225
- `[in] receiver`: The `this` object passed to the called function.
225
226
- `[in] callback`: The function which will be called when an asynchronous
226
227
operations ends. The given function is called from the main event loop thread.
227
- - `[in] resource_name`: Null-terminated strings that represents the
228
+ - `[in] resource_name`: Null-terminated string that represents the
228
229
identifier for the kind of resource that is being provided for diagnostic
229
230
information exposed by the async_hooks API.
230
231
@@ -242,7 +243,7 @@ explicit Napi::AsyncWorker(const Napi::Object& receiver, const Napi::Function& c
242
243
- ` [in] receiver ` : The ` this ` object passed to the called function.
243
244
- ` [in] callback ` : The function which will be called when an asynchronous
244
245
operations ends. The given function is called from the main event loop thread.
245
- - ` [in] resource_name ` : Null-terminated strings that represents the
246
+ - ` [in] resource_name ` : Null-terminated string that represents the
246
247
identifier for the kind of resource that is being provided for diagnostic
247
248
information exposed by the async_hooks API.
248
249
- ` [in] resource ` : Object associated with the asynchronous operation that
@@ -274,7 +275,7 @@ explicit Napi::AsyncWorker(Napi::Env env, const char* resource_name);
274
275
```
275
276
276
277
- ` [in] env ` : The environment in which to create the ` Napi::AsyncWorker ` .
277
- - ` [in] resource_name ` : Null-terminated strings that represents the
278
+ - ` [in] resource_name ` : Null-terminated string that represents the
278
279
identifier for the kind of resource that is being provided for diagnostic
279
280
information exposed by the async_hooks API.
280
281
@@ -290,7 +291,7 @@ explicit Napi::AsyncWorker(Napi::Env env, const char* resource_name, const Napi:
290
291
```
291
292
292
293
- `[in] env`: The environment in which to create the `Napi::AsyncWorker`.
293
- - `[in] resource_name`: Null-terminated strings that represents the
294
+ - `[in] resource_name`: Null-terminated string that represents the
294
295
identifier for the kind of resource that is being provided for diagnostic
295
296
information exposed by the async_hooks API.
296
297
- `[in] resource`: Object associated with the asynchronous operation that
@@ -333,7 +334,7 @@ function runs in the background out of the **event loop** thread and at the end
333
334
the ` Napi::AsyncWorker::OnOK ` or ` Napi::AsyncWorker::OnError ` function will be
334
335
called and are executed as part of the event loop.
335
336
336
- The code below show a basic example of ` Napi::AsyncWorker ` the implementation:
337
+ The code below shows a basic example of ` Napi::AsyncWorker ` the implementation:
337
338
338
339
``` cpp
339
340
#include < napi.h>
@@ -371,7 +372,7 @@ the work on the `Napi::AsyncWorker::Execute` method is done the
371
372
` Napi::AsyncWorker::OnOk ` method is called and the results return back to
372
373
JavaScript invoking the stored callback with its associated environment.
373
374
374
- The following code shows an example on how to create and use an ` Napi::AsyncWorker `
375
+ The following code shows an example of how to create and use an ` Napi::AsyncWorker ` .
375
376
376
377
``` cpp
377
378
#include < napi.h>
@@ -382,7 +383,7 @@ The following code shows an example on how to create and use an `Napi::AsyncWork
382
383
use namespace Napi ;
383
384
384
385
Value Echo (const CallbackInfo& info) {
385
- // You need to check the input data here
386
+ // You need to validate the arguments here.
386
387
Function cb = info[ 1] .As<Function >();
387
388
std::string in = info[ 0] .As<String >();
388
389
EchoWorker* wk = new EchoWorker(cb, in);
0 commit comments