@@ -14,7 +14,7 @@ easy way to do this. These APIs provide two types --
14
14
[ ` Napi::ThreadSafeFunctionEx ` ] ( threadsafe_function_ex.md ) -- as well as APIs to
15
15
create, destroy, and call objects of this type. The differences between the two
16
16
are subtle and are [ highlighted below] ( #implementation-differences ) . Regardless
17
- of which type you choose, the API between the two are similar.
17
+ of which type you choose, the APIs between the two are similar.
18
18
19
19
` Napi::ThreadSafeFunction[Ex]::New() ` creates a persistent reference that holds
20
20
a JavaScript function which can be called from multiple threads. The calls
@@ -44,11 +44,11 @@ reaches zero, no further threads can start making use of it by calling
44
44
45
45
The choice between ` Napi::ThreadSafeFunction ` and ` Napi::ThreadSafeFunctionEx `
46
46
depends largely on how you plan to execute your native C++ code (the "callback")
47
- on the Node thread.
47
+ on the Node.js thread.
48
48
49
49
### [ ` Napi::ThreadSafeFunction ` ] ( threadsafe_function.md )
50
50
51
- This API is designed without N-API 5 native support for [ optional JavaScript
51
+ This API is designed without N-API 5 native support for [ the optional JavaScript
52
52
function callback feature] ( https://github.com/nodejs/node/commit/53297e66cb ) .
53
53
` ::New ` methods that do not have a ` Function ` parameter will construct a
54
54
_ new_ , no-op ` Function ` on the environment to pass to the underlying N-API
@@ -62,12 +62,12 @@ This API has some dynamic functionality, in that:
62
62
- Different C++ data types may be passed with each call of ` [Non]BlockingCall() `
63
63
to match the specific data type as specified in the ` CallJs ` callback.
64
64
65
- However, this functionality comes with some ** additional overhead** and
65
+ Note that this functionality comes with some ** additional overhead** and
66
66
situational ** memory leaks** :
67
- - The API acts as a "middle-man " between the underlying
67
+ - The API acts as a "broker " between the underlying
68
68
` napi_threadsafe_function ` , and dynamically constructs a wrapper for your
69
69
callback on the heap for every call to ` [Non]BlockingCall() ` .
70
- - In acting in this "middle-man " fashion, the API will call the underlying "make
70
+ - In acting in this "broker " fashion, the API will call the underlying "make
71
71
call" N-API method on this packaged item. If the API has determined the
72
72
thread-safe function is no longer accessible (eg. all threads have released yet
73
73
there are still items on the queue), ** the callback passed to
@@ -88,15 +88,15 @@ drawbacks listed above. The API is designed with N-API 5's support of an
88
88
optional function callback. The API will correctly allow developers to pass
89
89
` std::nullptr ` instead of a ` const Function& ` for the callback function
90
90
specified in ` ::New ` . It also provides helper APIs to _ target_ N-API 4 and
91
- construct a no-op ` Function ` ** or** to target N-API 5 and "construct" an
91
+ construct a no-op ` Function ` ** or** to target N-API 5 and "construct" a
92
92
` std::nullptr ` callback. This allows a single codebase to use the same APIs,
93
93
with just a switch of the ` NAPI_VERSION ` compile-time constant.
94
94
95
- The removal of the dynamic call functionality has the additional side effects :
96
- - The API does _ not_ act as a "middle-man " compared to the non-` Ex ` . Once Node
95
+ The removal of the dynamic call functionality has the following implications :
96
+ - The API does _ not_ act as a "broker " compared to the non-` Ex ` . Once Node.js
97
97
finalizes the thread-safe function, the ` CallJs ` callback will execute with an
98
- empty ` Napi::Env ` for any remaining items on the queue. This provides the the
99
- ability to handle any necessary clean up of the item's data.
98
+ empty ` Napi::Env ` for any remaining items on the queue. This provides the
99
+ ability to handle any necessary cleanup of the item's data.
100
100
- The callback _ does_ receive the context as a parameter, so a call to
101
101
` GetContext() ` is _ not_ necessary. This context type is specified as the
102
102
** first type argument** specified to ` ::New ` , ensuring type safety.
0 commit comments