diff --git a/README.md b/README.md index ff4319553..6b0df4deb 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ The following is the documentation for node-addon-api. - [AsyncWorker Variants](doc/async_worker_variants.md) - [Thread-safe Functions](doc/threadsafe.md) - [ThreadSafeFunction](doc/threadsafe_function.md) - - [ThreadSafeFunctionEx](doc/threadsafe_function_ex.md) + - [TypedThreadSafeFunction](doc/typed_threadsafe_function.md) - [Promises](doc/promises.md) - [Version management](doc/version_management.md) diff --git a/doc/threadsafe.md b/doc/threadsafe.md index b867c8cab..22bb399fc 100644 --- a/doc/threadsafe.md +++ b/doc/threadsafe.md @@ -11,40 +11,40 @@ communicate with the addon's main thread so that the main thread can invoke the JavaScript function on their behalf. The thread-safe function APIs provide an easy way to do this. These APIs provide two types -- [`Napi::ThreadSafeFunction`](threadsafe_function.md) and -[`Napi::ThreadSafeFunctionEx`](threadsafe_function_ex.md) -- as well as APIs to -create, destroy, and call objects of this type. The differences between the two -are subtle and are [highlighted below](#implementation-differences). Regardless -of which type you choose, the APIs between the two are similar. +[`Napi::TypedThreadSafeFunction`](typed_threadsafe_function.md) -- as well as +APIs to create, destroy, and call objects of this type. The differences between +the two are subtle and are [highlighted below](#implementation-differences). +Regardless of which type you choose, the APIs between the two are similar. -`Napi::ThreadSafeFunction[Ex]::New()` creates a persistent reference that holds -a JavaScript function which can be called from multiple threads. The calls +`Napi::[Typed]ThreadSafeFunction::New()` creates a persistent reference that +holds a JavaScript function which can be called from multiple threads. The calls happen asynchronously. This means that values with which the JavaScript callback is to be called will be placed in a queue, and, for each value in the queue, a call will eventually be made to the JavaScript function. -`Napi::ThreadSafeFunction[Ex]` objects are destroyed when every thread which +`Napi::[Typed]ThreadSafeFunction` objects are destroyed when every thread which uses the object has called `Release()` or has received a return status of `napi_closing` in response to a call to `BlockingCall()` or `NonBlockingCall()`. -The queue is emptied before the `Napi::ThreadSafeFunction[Ex]` is destroyed. It -is important that `Release()` be the last API call made in conjunction with a -given `Napi::ThreadSafeFunction[Ex]`, because after the call completes, there is -no guarantee that the `Napi::ThreadSafeFunction[Ex]` is still allocated. For the -same reason it is also important that no more use be made of a thread-safe -function after receiving a return value of `napi_closing` in response to a call -to `BlockingCall()` or `NonBlockingCall()`. Data associated with the -`Napi::ThreadSafeFunction[Ex]` can be freed in its `Finalizer` callback which -was passed to `ThreadSafeFunction[Ex]::New()`. - -Once the number of threads making use of a `Napi::ThreadSafeFunction[Ex]` +The queue is emptied before the `Napi::[Typed]ThreadSafeFunction` is destroyed. +It is important that `Release()` be the last API call made in conjunction with a +given `Napi::[Typed]ThreadSafeFunction`, because after the call completes, there +is no guarantee that the `Napi::[Typed]ThreadSafeFunction` is still allocated. +For the same reason it is also important that no more use be made of a +thread-safe function after receiving a return value of `napi_closing` in +response to a call to `BlockingCall()` or `NonBlockingCall()`. Data associated +with the `Napi::[Typed]ThreadSafeFunction` can be freed in its `Finalizer` +callback which was passed to `[Typed]ThreadSafeFunction::New()`. + +Once the number of threads making use of a `Napi::[Typed]ThreadSafeFunction` reaches zero, no further threads can start making use of it by calling `Acquire()`. In fact, all subsequent API calls associated with it, except `Release()`, will return an error value of `napi_closing`. ## Implementation Differences -The choice between `Napi::ThreadSafeFunction` and `Napi::ThreadSafeFunctionEx` -depends largely on how you plan to execute your native C++ code (the "callback") -on the Node.js thread. +The choice between `Napi::ThreadSafeFunction` and +`Napi::TypedThreadSafeFunction` depends largely on how you plan to execute your +native C++ code (the "callback") on the Node.js thread. ### [`Napi::ThreadSafeFunction`](threadsafe_function.md) @@ -64,13 +64,13 @@ This API has some dynamic functionality, in that: Note that this functionality comes with some **additional overhead** and situational **memory leaks**: -- The API acts as a "broker" between the underlying - `napi_threadsafe_function`, and dynamically constructs a wrapper for your - callback on the heap for every call to `[Non]BlockingCall()`. +- The API acts as a "broker" between the underlying `napi_threadsafe_function`, + and dynamically constructs a wrapper for your callback on the heap for every + call to `[Non]BlockingCall()`. - In acting in this "broker" fashion, the API will call the underlying "make call" N-API method on this packaged item. If the API has determined the - thread-safe function is no longer accessible (eg. all threads have released yet - there are still items on the queue), **the callback passed to + thread-safe function is no longer accessible (eg. all threads have released + yet there are still items on the queue), **the callback passed to [Non]BlockingCall will not execute**. This means it is impossible to perform clean-up for calls that never execute their `CallJs` callback. **This may lead to memory leaks** if you are dynamically allocating memory. @@ -81,9 +81,9 @@ situational **memory leaks**: _type-safe_, as the method returns an object that can be "any-casted", instead of having a static type. -### [`Napi::ThreadSafeFunctionEx`](threadsafe_function_ex.md) +### [`Napi::TypedThreadSafeFunction`](typed_threadsafe_function.md) -The `ThreadSafeFunctionEx` class is a new implementation to address the +The `TypedThreadSafeFunction` class is a new implementation to address the drawbacks listed above. The API is designed with N-API 5's support of an optional function callback. The API will correctly allow developers to pass `std::nullptr` instead of a `const Function&` for the callback function @@ -112,7 +112,7 @@ The removal of the dynamic call functionality has the following implications: ### Usage Suggestions -In summary, it may be best to use `Napi::ThreadSafeFunctionEx` if: +In summary, it may be best to use `Napi::TypedThreadSafeFunction` if: - static, compile-time support for targeting N-API 4 or 5+ with an optional JavaScript callback feature is desired; diff --git a/doc/threadsafe_function_ex.md b/doc/typed_threadsafe_function.md similarity index 78% rename from doc/threadsafe_function_ex.md rename to doc/typed_threadsafe_function.md index fdc56ecae..e0d29807f 100644 --- a/doc/threadsafe_function_ex.md +++ b/doc/typed_threadsafe_function.md @@ -1,11 +1,11 @@ -# ThreadSafeFunctionEx - -The `Napi::ThreadSafeFunctionEx` type provides APIs for threads to communicate -with the addon's main thread to invoke JavaScript functions on their behalf. The -type is a three-argument templated class, each argument representing the type -of: -- `ContextType = std::nullptr_t`: The thread-safe function's context. By default, - a TSFN has no context. +# TypedThreadSafeFunction + +The `Napi::TypedThreadSafeFunction` type provides APIs for threads to +communicate with the addon's main thread to invoke JavaScript functions on their +behalf. The type is a three-argument templated class, each argument representing +the type of: +- `ContextType = std::nullptr_t`: The thread-safe function's context. By + default, a TSFN has no context. - `DataType = void*`: The data to use in the native callback. By default, a TSFN can accept any data type. - `Callback = void(*)(Napi::Env, Napi::Function jsCallback, ContextType*, @@ -21,31 +21,31 @@ APIs](threadsafe.md#implementation-differences). ### Constructor -Creates a new empty instance of `Napi::ThreadSafeFunctionEx`. +Creates a new empty instance of `Napi::TypedThreadSafeFunction`. ```cpp -Napi::Function::ThreadSafeFunctionEx::ThreadSafeFunctionEx(); +Napi::Function::TypedThreadSafeFunction::TypedThreadSafeFunction(); ``` ### Constructor -Creates a new instance of the `Napi::ThreadSafeFunctionEx` object. +Creates a new instance of the `Napi::TypedThreadSafeFunction` object. ```cpp -Napi::ThreadSafeFunctionEx::ThreadSafeFunctionEx(napi_threadsafe_function tsfn); +Napi::TypedThreadSafeFunction::TypedThreadSafeFunction(napi_threadsafe_function tsfn); ``` - `tsfn`: The `napi_threadsafe_function` which is a handle for an existing thread-safe function. -Returns a non-empty `Napi::ThreadSafeFunctionEx` instance. To ensure the API +Returns a non-empty `Napi::TypedThreadSafeFunction` instance. To ensure the API statically handles the correct return type for `GetContext()` and `[Non]BlockingCall()`, pass the proper template arguments to -`Napi::ThreadSafeFunctionEx`. +`Napi::TypedThreadSafeFunction`. ### New -Creates a new instance of the `Napi::ThreadSafeFunctionEx` object. The `New` +Creates a new instance of the `Napi::TypedThreadSafeFunction` object. The `New` function has several overloads for the various optional parameters: skip the optional parameter for that specific overload. @@ -72,11 +72,11 @@ New(napi_env env, - `maxQueueSize`: Maximum size of the queue. `0` for no limit. - `initialThreadCount`: The initial number of threads, including the main thread, which will be making use of this function. -- `[optional] context`: Data to attach to the resulting `ThreadSafeFunction`. - It can be retreived via `GetContext()`. +- `[optional] context`: Data to attach to the resulting `ThreadSafeFunction`. It + can be retreived via `GetContext()`. - `[optional] finalizeCallback`: Function to call when the - `ThreadSafeFunctionEx` is being destroyed. This callback will be invoked on - the main thread when the thread-safe function is about to be destroyed. It + `TypedThreadSafeFunction` is being destroyed. This callback will be invoked + on the main thread when the thread-safe function is about to be destroyed. It receives the context and the finalize data given during construction (if given), and provides an opportunity for cleaning up after the threads e.g. by calling `uv_thread_join()`. It is important that, aside from the main loop @@ -85,7 +85,7 @@ New(napi_env env, FinalizerDataType* data, ContextType* hint)`. - `[optional] data`: Data to be passed to `finalizeCallback`. -Returns a non-empty `Napi::ThreadSafeFunctionEx` instance. +Returns a non-empty `Napi::TypedThreadSafeFunction` instance. Depending on the targetted `NAPI_VERSION`, the API has different implementations for `CallbackType callback`. @@ -93,7 +93,7 @@ for `CallbackType callback`. When targetting version 4, `callback` may be: - of type `const Function&` - not provided as a parameter, in which case the API creates a new no-op -`Function` + `Function` When targetting version 5+, `callback` may be: - of type `const Function&` @@ -106,7 +106,7 @@ Adds a thread to this thread-safe function object, indicating that a new thread will start making use of the thread-safe function. ```cpp -napi_status Napi::ThreadSafeFunctionEx::Acquire() +napi_status Napi::TypedThreadSafeFunction::Acquire() ``` Returns one of: @@ -124,7 +124,7 @@ has undefined results in the current thread, as the thread-safe function may have been destroyed. ```cpp -napi_status Napi::ThreadSafeFunctionEx::Release() +napi_status Napi::TypedThreadSafeFunction::Release() ``` Returns one of: @@ -135,18 +135,18 @@ Returns one of: ### Abort -"Aborts" the thread-safe function. This will cause all subsequent APIs associated -with the thread-safe function except `Release()` to return `napi_closing` even -before its reference count reaches zero. In particular, `BlockingCall` and -`NonBlockingCall()` will return `napi_closing`, thus informing the threads that -it is no longer possible to make asynchronous calls to the thread-safe function. -This can be used as a criterion for terminating the thread. Upon receiving a -return value of `napi_closing` from a thread-safe function call a thread must -make no further use of the thread-safe function because it is no longer -guaranteed to be allocated. +"Aborts" the thread-safe function. This will cause all subsequent APIs +associated with the thread-safe function except `Release()` to return +`napi_closing` even before its reference count reaches zero. In particular, +`BlockingCall` and `NonBlockingCall()` will return `napi_closing`, thus +informing the threads that it is no longer possible to make asynchronous calls +to the thread-safe function. This can be used as a criterion for terminating the +thread. Upon receiving a return value of `napi_closing` from a thread-safe +function call a thread must make no further use of the thread-safe function +because it is no longer guaranteed to be allocated. ```cpp -napi_status Napi::ThreadSafeFunctionEx::Abort() +napi_status Napi::TypedThreadSafeFunction::Abort() ``` Returns one of: @@ -165,13 +165,13 @@ Calls the Javascript function in either a blocking or non-blocking fashion. preventing data from being successfully added to the queue. ```cpp -napi_status Napi::ThreadSafeFunctionEx::BlockingCall(DataType* data = nullptr) const +napi_status Napi::TypedThreadSafeFunction::BlockingCall(DataType* data = nullptr) const -napi_status Napi::ThreadSafeFunctionEx::NonBlockingCall(DataType* data = nullptr) const +napi_status Napi::TypedThreadSafeFunction::NonBlockingCall(DataType* data = nullptr) const ``` - `[optional] data`: Data to pass to the callback which was passed to - `ThreadSafeFunctionEx::New()`. + `TypedThreadSafeFunction::New()`. Returns one of: - `napi_ok`: `data` was successfully added to the queue. @@ -196,7 +196,7 @@ using namespace Napi; using Context = Reference; using DataType = int; void CallJs(Napi::Env env, Function callback, Context *context, DataType *data); -using TSFN = ThreadSafeFunctionEx; +using TSFN = TypedThreadSafeFunction; using FinalizerDataType = void; std::thread nativeThread; diff --git a/napi-inl.h b/napi-inl.h index 624f36c84..55273b662 100644 --- a/napi-inl.h +++ b/napi-inl.h @@ -4377,7 +4377,7 @@ inline void AsyncWorker::OnWorkComplete(Napi::Env /*env*/, napi_status status) { #if (NAPI_VERSION > 3 && !defined(__wasm32__)) //////////////////////////////////////////////////////////////////////////////// -// ThreadSafeFunctionEx class +// TypedThreadSafeFunction class //////////////////////////////////////////////////////////////////////////////// // Starting with NAPI 5, the JavaScript function `func` parameter of @@ -4387,11 +4387,11 @@ inline void AsyncWorker::OnWorkComplete(Napi::Env /*env*/, napi_status status) { template template -inline ThreadSafeFunctionEx -ThreadSafeFunctionEx::New( +inline TypedThreadSafeFunction +TypedThreadSafeFunction::New( napi_env env, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context) { - ThreadSafeFunctionEx tsfn; + TypedThreadSafeFunction tsfn; napi_status status = napi_create_threadsafe_function( env, nullptr, nullptr, String::From(env, resourceName), maxQueueSize, @@ -4399,7 +4399,7 @@ ThreadSafeFunctionEx::New( CallJsInternal, &tsfn._tsfn); if (status != napi_ok) { NAPI_THROW_IF_FAILED(env, status, - ThreadSafeFunctionEx()); + TypedThreadSafeFunction()); } return tsfn; @@ -4409,11 +4409,11 @@ ThreadSafeFunctionEx::New( template template -inline ThreadSafeFunctionEx -ThreadSafeFunctionEx::New( +inline TypedThreadSafeFunction +TypedThreadSafeFunction::New( napi_env env, const Object &resource, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context) { - ThreadSafeFunctionEx tsfn; + TypedThreadSafeFunction tsfn; napi_status status = napi_create_threadsafe_function( env, nullptr, resource, String::From(env, resourceName), maxQueueSize, @@ -4421,7 +4421,7 @@ ThreadSafeFunctionEx::New( &tsfn._tsfn); if (status != napi_ok) { NAPI_THROW_IF_FAILED(env, status, - ThreadSafeFunctionEx()); + TypedThreadSafeFunction()); } return tsfn; @@ -4432,12 +4432,12 @@ template template -inline ThreadSafeFunctionEx -ThreadSafeFunctionEx::New( +inline TypedThreadSafeFunction +TypedThreadSafeFunction::New( napi_env env, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context, Finalizer finalizeCallback, FinalizerDataType *data) { - ThreadSafeFunctionEx tsfn; + TypedThreadSafeFunction tsfn; auto *finalizeData = new details::ThreadSafeFinalize( @@ -4451,7 +4451,7 @@ ThreadSafeFunctionEx::New( if (status != napi_ok) { delete finalizeData; NAPI_THROW_IF_FAILED(env, status, - ThreadSafeFunctionEx()); + TypedThreadSafeFunction()); } return tsfn; @@ -4462,12 +4462,12 @@ template template -inline ThreadSafeFunctionEx -ThreadSafeFunctionEx::New( +inline TypedThreadSafeFunction +TypedThreadSafeFunction::New( napi_env env, const Object &resource, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context, Finalizer finalizeCallback, FinalizerDataType *data) { - ThreadSafeFunctionEx tsfn; + TypedThreadSafeFunction tsfn; auto *finalizeData = new details::ThreadSafeFinalize( @@ -4481,7 +4481,7 @@ ThreadSafeFunctionEx::New( if (status != napi_ok) { delete finalizeData; NAPI_THROW_IF_FAILED(env, status, - ThreadSafeFunctionEx()); + TypedThreadSafeFunction()); } return tsfn; @@ -4492,11 +4492,11 @@ ThreadSafeFunctionEx::New( template template -inline ThreadSafeFunctionEx -ThreadSafeFunctionEx::New( +inline TypedThreadSafeFunction +TypedThreadSafeFunction::New( napi_env env, const Function &callback, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context) { - ThreadSafeFunctionEx tsfn; + TypedThreadSafeFunction tsfn; napi_status status = napi_create_threadsafe_function( env, callback, nullptr, String::From(env, resourceName), maxQueueSize, @@ -4504,7 +4504,7 @@ ThreadSafeFunctionEx::New( &tsfn._tsfn); if (status != napi_ok) { NAPI_THROW_IF_FAILED(env, status, - ThreadSafeFunctionEx()); + TypedThreadSafeFunction()); } return tsfn; @@ -4514,12 +4514,12 @@ ThreadSafeFunctionEx::New( template template -inline ThreadSafeFunctionEx -ThreadSafeFunctionEx::New( +inline TypedThreadSafeFunction +TypedThreadSafeFunction::New( napi_env env, const Function &callback, const Object &resource, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context) { - ThreadSafeFunctionEx tsfn; + TypedThreadSafeFunction tsfn; napi_status status = napi_create_threadsafe_function( env, callback, resource, String::From(env, resourceName), maxQueueSize, @@ -4527,7 +4527,7 @@ ThreadSafeFunctionEx::New( &tsfn._tsfn); if (status != napi_ok) { NAPI_THROW_IF_FAILED(env, status, - ThreadSafeFunctionEx()); + TypedThreadSafeFunction()); } return tsfn; @@ -4538,12 +4538,12 @@ template template -inline ThreadSafeFunctionEx -ThreadSafeFunctionEx::New( +inline TypedThreadSafeFunction +TypedThreadSafeFunction::New( napi_env env, const Function &callback, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context, Finalizer finalizeCallback, FinalizerDataType *data) { - ThreadSafeFunctionEx tsfn; + TypedThreadSafeFunction tsfn; auto *finalizeData = new details::ThreadSafeFinalize( @@ -4557,7 +4557,7 @@ ThreadSafeFunctionEx::New( if (status != napi_ok) { delete finalizeData; NAPI_THROW_IF_FAILED(env, status, - ThreadSafeFunctionEx()); + TypedThreadSafeFunction()); } return tsfn; @@ -4568,18 +4568,18 @@ template template -inline ThreadSafeFunctionEx -ThreadSafeFunctionEx::New( +inline TypedThreadSafeFunction +TypedThreadSafeFunction::New( napi_env env, CallbackType callback, const Object &resource, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context, Finalizer finalizeCallback, FinalizerDataType *data) { - ThreadSafeFunctionEx tsfn; + TypedThreadSafeFunction tsfn; auto *finalizeData = new details::ThreadSafeFinalize( {data, finalizeCallback}); napi_status status = napi_create_threadsafe_function( - env, details::DefaultCallbackWrapper>(env, callback), resource, + env, details::DefaultCallbackWrapper>(env, callback), resource, String::From(env, resourceName), maxQueueSize, initialThreadCount, finalizeData, details::ThreadSafeFinalize:: @@ -4588,7 +4588,7 @@ ThreadSafeFunctionEx::New( if (status != napi_ok) { delete finalizeData; NAPI_THROW_IF_FAILED(env, status, - ThreadSafeFunctionEx()); + TypedThreadSafeFunction()); } return tsfn; @@ -4596,19 +4596,19 @@ ThreadSafeFunctionEx::New( template -inline ThreadSafeFunctionEx::ThreadSafeFunctionEx() +inline TypedThreadSafeFunction::TypedThreadSafeFunction() : _tsfn() {} template -inline ThreadSafeFunctionEx:: - ThreadSafeFunctionEx(napi_threadsafe_function tsfn) +inline TypedThreadSafeFunction:: + TypedThreadSafeFunction(napi_threadsafe_function tsfn) : _tsfn(tsfn) {} template -inline ThreadSafeFunctionEx:: +inline TypedThreadSafeFunction:: operator napi_threadsafe_function() const { return _tsfn; } @@ -4616,7 +4616,7 @@ operator napi_threadsafe_function() const { template inline napi_status -ThreadSafeFunctionEx::BlockingCall( +TypedThreadSafeFunction::BlockingCall( DataType *data) const { return napi_call_threadsafe_function(_tsfn, data, napi_tsfn_blocking); } @@ -4624,7 +4624,7 @@ ThreadSafeFunctionEx::BlockingCall( template inline napi_status -ThreadSafeFunctionEx::NonBlockingCall( +TypedThreadSafeFunction::NonBlockingCall( DataType *data) const { return napi_call_threadsafe_function(_tsfn, data, napi_tsfn_nonblocking); } @@ -4632,7 +4632,7 @@ ThreadSafeFunctionEx::NonBlockingCall( template inline void -ThreadSafeFunctionEx::Ref(napi_env env) const { +TypedThreadSafeFunction::Ref(napi_env env) const { if (_tsfn != nullptr) { napi_status status = napi_ref_threadsafe_function(env, _tsfn); NAPI_THROW_IF_FAILED_VOID(env, status); @@ -4642,7 +4642,7 @@ ThreadSafeFunctionEx::Ref(napi_env env) const { template inline void -ThreadSafeFunctionEx::Unref(napi_env env) const { +TypedThreadSafeFunction::Unref(napi_env env) const { if (_tsfn != nullptr) { napi_status status = napi_unref_threadsafe_function(env, _tsfn); NAPI_THROW_IF_FAILED_VOID(env, status); @@ -4652,31 +4652,31 @@ ThreadSafeFunctionEx::Unref(napi_env env) const { template inline napi_status -ThreadSafeFunctionEx::Acquire() const { +TypedThreadSafeFunction::Acquire() const { return napi_acquire_threadsafe_function(_tsfn); } template inline napi_status -ThreadSafeFunctionEx::Release() { +TypedThreadSafeFunction::Release() { return napi_release_threadsafe_function(_tsfn, napi_tsfn_release); } template inline napi_status -ThreadSafeFunctionEx::Abort() { +TypedThreadSafeFunction::Abort() { return napi_release_threadsafe_function(_tsfn, napi_tsfn_abort); } template inline ContextType * -ThreadSafeFunctionEx::GetContext() const { +TypedThreadSafeFunction::GetContext() const { void *context; napi_status status = napi_get_threadsafe_function_context(_tsfn, &context); - NAPI_FATAL_IF_FAILED(status, "ThreadSafeFunctionEx::GetContext", + NAPI_FATAL_IF_FAILED(status, "TypedThreadSafeFunction::GetContext", "napi_get_threadsafe_function_context"); return static_cast(context); } @@ -4684,7 +4684,7 @@ ThreadSafeFunctionEx::GetContext() const { // static template -void ThreadSafeFunctionEx::CallJsInternal( +void TypedThreadSafeFunction::CallJsInternal( napi_env env, napi_value jsCallback, void *context, void *data) { details::CallJsWrapper( env, jsCallback, context, data); @@ -4695,7 +4695,7 @@ void ThreadSafeFunctionEx::CallJsInternal( template Napi::Function -ThreadSafeFunctionEx::EmptyFunctionFactory( +TypedThreadSafeFunction::EmptyFunctionFactory( Napi::Env env) { return Napi::Function::New(env, [](const CallbackInfo &cb) {}); } @@ -4704,7 +4704,7 @@ ThreadSafeFunctionEx::EmptyFunctionFactory( template Napi::Function -ThreadSafeFunctionEx::FunctionOrEmpty( +TypedThreadSafeFunction::FunctionOrEmpty( Napi::Env env, Napi::Function &callback) { if (callback.IsEmpty()) { return EmptyFunctionFactory(env); @@ -4717,7 +4717,7 @@ ThreadSafeFunctionEx::FunctionOrEmpty( template std::nullptr_t -ThreadSafeFunctionEx::EmptyFunctionFactory( +TypedThreadSafeFunction::EmptyFunctionFactory( Napi::Env /*env*/) { return nullptr; } @@ -4726,7 +4726,7 @@ ThreadSafeFunctionEx::EmptyFunctionFactory( template Napi::Function -ThreadSafeFunctionEx::FunctionOrEmpty( +TypedThreadSafeFunction::FunctionOrEmpty( Napi::Env /*env*/, Napi::Function &callback) { return callback; } diff --git a/napi.h b/napi.h index 88474a31f..b42b4b707 100644 --- a/napi.h +++ b/napi.h @@ -2244,12 +2244,12 @@ namespace Napi { napi_threadsafe_function _tsfn; }; - // A ThreadSafeFunctionEx by default has no context (nullptr) and can accept + // A TypedThreadSafeFunction by default has no context (nullptr) and can accept // any type (void) to its CallJs. template - class ThreadSafeFunctionEx { + class TypedThreadSafeFunction { public: @@ -2270,7 +2270,7 @@ namespace Napi { // Creates a new threadsafe function with: // Callback [missing] Resource [missing] Finalizer [missing] template - static ThreadSafeFunctionEx + static TypedThreadSafeFunction New(napi_env env, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context = nullptr); @@ -2278,7 +2278,7 @@ namespace Napi { // Creates a new threadsafe function with: // Callback [missing] Resource [passed] Finalizer [missing] template - static ThreadSafeFunctionEx + static TypedThreadSafeFunction New(napi_env env, const Object &resource, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context = nullptr); @@ -2288,7 +2288,7 @@ namespace Napi { // Callback [missing] Resource [missing] Finalizer [passed] template - static ThreadSafeFunctionEx + static TypedThreadSafeFunction New(napi_env env, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context, Finalizer finalizeCallback, FinalizerDataType *data = nullptr); @@ -2298,7 +2298,7 @@ namespace Napi { // Callback [missing] Resource [passed] Finalizer [passed] template - static ThreadSafeFunctionEx + static TypedThreadSafeFunction New(napi_env env, const Object &resource, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context, Finalizer finalizeCallback, FinalizerDataType *data = nullptr); @@ -2308,7 +2308,7 @@ namespace Napi { // Creates a new threadsafe function with: // Callback [passed] Resource [missing] Finalizer [missing] template - static ThreadSafeFunctionEx + static TypedThreadSafeFunction New(napi_env env, const Function &callback, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context = nullptr); @@ -2317,7 +2317,7 @@ namespace Napi { // Creates a new threadsafe function with: // Callback [passed] Resource [passed] Finalizer [missing] template - static ThreadSafeFunctionEx + static TypedThreadSafeFunction New(napi_env env, const Function &callback, const Object &resource, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context = nullptr); @@ -2327,7 +2327,7 @@ namespace Napi { // Callback [passed] Resource [missing] Finalizer [passed] template - static ThreadSafeFunctionEx + static TypedThreadSafeFunction New(napi_env env, const Function &callback, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context, Finalizer finalizeCallback, FinalizerDataType *data = nullptr); @@ -2337,14 +2337,14 @@ namespace Napi { // Callback [passed] Resource [passed] Finalizer [passed] template - static ThreadSafeFunctionEx + static TypedThreadSafeFunction New(napi_env env, CallbackType callback, const Object &resource, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context, Finalizer finalizeCallback, FinalizerDataType *data = nullptr); - ThreadSafeFunctionEx(); - ThreadSafeFunctionEx( + TypedThreadSafeFunction(); + TypedThreadSafeFunction( napi_threadsafe_function tsFunctionValue); operator napi_threadsafe_function() const; @@ -2376,7 +2376,7 @@ namespace Napi { private: template - static ThreadSafeFunctionEx + static TypedThreadSafeFunction New(napi_env env, const Function &callback, const Object &resource, ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, ContextType *context, diff --git a/test/binding.cc b/test/binding.cc index fe3a3cd5b..b46cb4df8 100644 --- a/test/binding.cc +++ b/test/binding.cc @@ -49,12 +49,12 @@ Object InitThreadSafeFunctionPtr(Env env); Object InitThreadSafeFunctionSum(Env env); Object InitThreadSafeFunctionUnref(Env env); Object InitThreadSafeFunction(Env env); -Object InitThreadSafeFunctionExCtx(Env env); -Object InitThreadSafeFunctionExExistingTsfn(Env env); -Object InitThreadSafeFunctionExPtr(Env env); -Object InitThreadSafeFunctionExSum(Env env); -Object InitThreadSafeFunctionExUnref(Env env); -Object InitThreadSafeFunctionEx(Env env); +Object InitTypedThreadSafeFunctionCtx(Env env); +Object InitTypedThreadSafeFunctionExistingTsfn(Env env); +Object InitTypedThreadSafeFunctionPtr(Env env); +Object InitTypedThreadSafeFunctionSum(Env env); +Object InitTypedThreadSafeFunctionUnref(Env env); +Object InitTypedThreadSafeFunction(Env env); #endif Object InitTypedArray(Env env); Object InitObjectWrap(Env env); @@ -114,13 +114,13 @@ Object Init(Env env, Object exports) { exports.Set("threadsafe_function_ptr", InitThreadSafeFunctionPtr(env)); exports.Set("threadsafe_function_sum", InitThreadSafeFunctionSum(env)); exports.Set("threadsafe_function_unref", InitThreadSafeFunctionUnref(env)); - exports.Set("threadsafe_function", InitThreadSafeFunctionEx(env)); - exports.Set("threadsafe_function_ex_ctx", InitThreadSafeFunctionExCtx(env)); - exports.Set("threadsafe_function_ex_existing_tsfn", InitThreadSafeFunctionExExistingTsfn(env)); - exports.Set("threadsafe_function_ex_ptr", InitThreadSafeFunctionExPtr(env)); - exports.Set("threadsafe_function_ex_sum", InitThreadSafeFunctionExSum(env)); - exports.Set("threadsafe_function_ex_unref", InitThreadSafeFunctionExUnref(env)); - exports.Set("threadsafe_function_ex", InitThreadSafeFunctionEx(env)); + exports.Set("threadsafe_function", InitTypedThreadSafeFunction(env)); + exports.Set("typed_threadsafe_function_ctx", InitTypedThreadSafeFunctionCtx(env)); + exports.Set("typed_threadsafe_function_existing_tsfn", InitTypedThreadSafeFunctionExistingTsfn(env)); + exports.Set("typed_threadsafe_function_ptr", InitTypedThreadSafeFunctionPtr(env)); + exports.Set("typed_threadsafe_function_sum", InitTypedThreadSafeFunctionSum(env)); + exports.Set("typed_threadsafe_function_unref", InitTypedThreadSafeFunctionUnref(env)); + exports.Set("typed_threadsafe_function", InitTypedThreadSafeFunction(env)); #endif exports.Set("typedarray", InitTypedArray(env)); exports.Set("objectwrap", InitObjectWrap(env)); diff --git a/test/binding.gyp b/test/binding.gyp index 7f64e7f51..90dee4565 100644 --- a/test/binding.gyp +++ b/test/binding.gyp @@ -36,18 +36,18 @@ 'object/set_property.cc', 'promise.cc', 'run_script.cc', - 'threadsafe_function_ex/threadsafe_function_ex_ctx.cc', - 'threadsafe_function_ex/threadsafe_function_ex_existing_tsfn.cc', - 'threadsafe_function_ex/threadsafe_function_ex_ptr.cc', - 'threadsafe_function_ex/threadsafe_function_ex_sum.cc', - 'threadsafe_function_ex/threadsafe_function_ex_unref.cc', - 'threadsafe_function_ex/threadsafe_function_ex.cc', 'threadsafe_function/threadsafe_function_ctx.cc', 'threadsafe_function/threadsafe_function_existing_tsfn.cc', 'threadsafe_function/threadsafe_function_ptr.cc', 'threadsafe_function/threadsafe_function_sum.cc', 'threadsafe_function/threadsafe_function_unref.cc', 'threadsafe_function/threadsafe_function.cc', + 'typed_threadsafe_function/typed_threadsafe_function_ctx.cc', + 'typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc', + 'typed_threadsafe_function/typed_threadsafe_function_ptr.cc', + 'typed_threadsafe_function/typed_threadsafe_function_sum.cc', + 'typed_threadsafe_function/typed_threadsafe_function_unref.cc', + 'typed_threadsafe_function/typed_threadsafe_function.cc', 'typedarray.cc', 'objectwrap.cc', 'objectwrap_constructor_exception.cc', diff --git a/test/index.js b/test/index.js index 060070590..3f8549999 100644 --- a/test/index.js +++ b/test/index.js @@ -44,18 +44,18 @@ let testModules = [ 'object/set_property', 'promise', 'run_script', - 'threadsafe_function_ex/threadsafe_function_ex_ctx', - 'threadsafe_function_ex/threadsafe_function_ex_existing_tsfn', - 'threadsafe_function_ex/threadsafe_function_ex_ptr', - 'threadsafe_function_ex/threadsafe_function_ex_sum', - 'threadsafe_function_ex/threadsafe_function_ex_unref', - 'threadsafe_function_ex/threadsafe_function_ex', 'threadsafe_function/threadsafe_function_ctx', 'threadsafe_function/threadsafe_function_existing_tsfn', 'threadsafe_function/threadsafe_function_ptr', 'threadsafe_function/threadsafe_function_sum', 'threadsafe_function/threadsafe_function_unref', 'threadsafe_function/threadsafe_function', + 'typed_threadsafe_function/typed_threadsafe_function_ctx', + 'typed_threadsafe_function/typed_threadsafe_function_existing_tsfn', + 'typed_threadsafe_function/typed_threadsafe_function_ptr', + 'typed_threadsafe_function/typed_threadsafe_function_sum', + 'typed_threadsafe_function/typed_threadsafe_function_unref', + 'typed_threadsafe_function/typed_threadsafe_function', 'typedarray', 'typedarray-bigint', 'objectwrap', diff --git a/test/threadsafe_function_ex/threadsafe_function_ex.cc b/test/typed_threadsafe_function/typed_threadsafe_function.cc similarity index 97% rename from test/threadsafe_function_ex/threadsafe_function_ex.cc rename to test/typed_threadsafe_function/typed_threadsafe_function.cc index cb604c17e..71f47b959 100644 --- a/test/threadsafe_function_ex/threadsafe_function_ex.cc +++ b/test/typed_threadsafe_function/typed_threadsafe_function.cc @@ -36,7 +36,7 @@ static void TSFNCallJS(Env env, Function jsCallback, } } -using TSFN = ThreadSafeFunctionEx; +using TSFN = TypedThreadSafeFunction; static TSFN tsfn; // Thread data to transmit to JS @@ -174,7 +174,7 @@ static Value StartThreadNoNative(const CallbackInfo& info) { return StartThreadInternal(info, ThreadSafeFunctionInfo::DEFAULT); } -Object InitThreadSafeFunctionEx(Env env) { +Object InitTypedThreadSafeFunction(Env env) { for (size_t index = 0; index < ARRAY_LENGTH; index++) { ints[index] = index; } diff --git a/test/threadsafe_function_ex/threadsafe_function_ex.js b/test/typed_threadsafe_function/typed_threadsafe_function.js similarity index 79% rename from test/threadsafe_function_ex/threadsafe_function_ex.js rename to test/typed_threadsafe_function/typed_threadsafe_function.js index 80a03840e..7aa8cc2ad 100644 --- a/test/threadsafe_function_ex/threadsafe_function_ex.js +++ b/test/typed_threadsafe_function/typed_threadsafe_function.js @@ -16,7 +16,7 @@ async function test(binding) { result.push(arrayLength - 1 - index); } return result; - })(binding.threadsafe_function_ex.ARRAY_LENGTH); + })(binding.typed_threadsafe_function.ARRAY_LENGTH); function testWithJSMarshaller({ threadStarter, @@ -26,11 +26,11 @@ async function test(binding) { launchSecondary }) { return new Promise((resolve) => { const array = []; - binding.threadsafe_function_ex[threadStarter](function testCallback(value) { + binding.typed_threadsafe_function[threadStarter](function testCallback(value) { array.push(value); if (array.length === quitAfter) { setImmediate(() => { - binding.threadsafe_function_ex.stopThread(common.mustCall(() => { + binding.typed_threadsafe_function.stopThread(common.mustCall(() => { resolve(array); }), !!abort); }); @@ -47,20 +47,20 @@ async function test(binding) { await new Promise(function testWithoutJSMarshaller(resolve) { let callCount = 0; - binding.threadsafe_function_ex.startThreadNoNative(function testCallback() { + binding.typed_threadsafe_function.startThreadNoNative(function testCallback() { callCount++; // The default call-into-JS implementation passes no arguments. assert.strictEqual(arguments.length, 0); - if (callCount === binding.threadsafe_function_ex.ARRAY_LENGTH) { + if (callCount === binding.typed_threadsafe_function.ARRAY_LENGTH) { setImmediate(() => { - binding.threadsafe_function_ex.stopThread(common.mustCall(() => { + binding.typed_threadsafe_function.stopThread(common.mustCall(() => { resolve(); }), false); }); } }, false /* abort */, false /* launchSecondary */, - binding.threadsafe_function_ex.MAX_QUEUE_SIZE); + binding.typed_threadsafe_function.MAX_QUEUE_SIZE); }); // Start the thread in blocking mode, and assert that all values are passed. @@ -68,8 +68,8 @@ async function test(binding) { assert.deepStrictEqual( await testWithJSMarshaller({ threadStarter: 'startThread', - maxQueueSize: binding.threadsafe_function_ex.MAX_QUEUE_SIZE, - quitAfter: binding.threadsafe_function_ex.ARRAY_LENGTH + maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE, + quitAfter: binding.typed_threadsafe_function.ARRAY_LENGTH }), expectedArray, ); @@ -80,7 +80,7 @@ async function test(binding) { await testWithJSMarshaller({ threadStarter: 'startThread', maxQueueSize: 0, - quitAfter: binding.threadsafe_function_ex.ARRAY_LENGTH + quitAfter: binding.typed_threadsafe_function.ARRAY_LENGTH }), expectedArray, ); @@ -90,8 +90,8 @@ async function test(binding) { assert.deepStrictEqual( await testWithJSMarshaller({ threadStarter: 'startThreadNonblocking', - maxQueueSize: binding.threadsafe_function_ex.MAX_QUEUE_SIZE, - quitAfter: binding.threadsafe_function_ex.ARRAY_LENGTH + maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE, + quitAfter: binding.typed_threadsafe_function.ARRAY_LENGTH }), expectedArray, ); @@ -101,7 +101,7 @@ async function test(binding) { assert.deepStrictEqual( await testWithJSMarshaller({ threadStarter: 'startThread', - maxQueueSize: binding.threadsafe_function_ex.MAX_QUEUE_SIZE, + maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE, quitAfter: 1 }), expectedArray, @@ -124,7 +124,7 @@ async function test(binding) { assert.deepStrictEqual( await testWithJSMarshaller({ threadStarter: 'startThreadNonblocking', - maxQueueSize: binding.threadsafe_function_ex.MAX_QUEUE_SIZE, + maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE, quitAfter: 1 }), expectedArray, @@ -137,7 +137,7 @@ async function test(binding) { await testWithJSMarshaller({ threadStarter: 'startThread', quitAfter: 1, - maxQueueSize: binding.threadsafe_function_ex.MAX_QUEUE_SIZE, + maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE, launchSecondary: true }), expectedArray, @@ -150,7 +150,7 @@ async function test(binding) { await testWithJSMarshaller({ threadStarter: 'startThreadNonblocking', quitAfter: 1, - maxQueueSize: binding.threadsafe_function_ex.MAX_QUEUE_SIZE, + maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE, launchSecondary: true }), expectedArray, @@ -162,7 +162,7 @@ async function test(binding) { (await testWithJSMarshaller({ threadStarter: 'startThread', quitAfter: 1, - maxQueueSize: binding.threadsafe_function_ex.MAX_QUEUE_SIZE, + maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE, abort: true })).indexOf(0), -1, @@ -186,7 +186,7 @@ async function test(binding) { (await testWithJSMarshaller({ threadStarter: 'startThreadNonblocking', quitAfter: 1, - maxQueueSize: binding.threadsafe_function_ex.MAX_QUEUE_SIZE, + maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE, abort: true })).indexOf(0), -1, diff --git a/test/threadsafe_function_ex/threadsafe_function_ex_ctx.cc b/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc similarity index 93% rename from test/threadsafe_function_ex/threadsafe_function_ex_ctx.cc rename to test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc index f186fc845..4ec3e368b 100644 --- a/test/threadsafe_function_ex/threadsafe_function_ex_ctx.cc +++ b/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc @@ -5,7 +5,7 @@ using namespace Napi; using ContextType = Reference; -using TSFN = ThreadSafeFunctionEx; +using TSFN = TypedThreadSafeFunction; namespace { @@ -55,7 +55,7 @@ TSFNWrap::TSFNWrap(const CallbackInfo &info) : ObjectWrap(info) { } // namespace -Object InitThreadSafeFunctionExCtx(Env env) { +Object InitTypedThreadSafeFunctionCtx(Env env) { return TSFNWrap::Init(env, Object::New(env)); } diff --git a/test/threadsafe_function_ex/threadsafe_function_ex_ctx.js b/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js similarity index 100% rename from test/threadsafe_function_ex/threadsafe_function_ex_ctx.js rename to test/typed_threadsafe_function/typed_threadsafe_function_ctx.js diff --git a/test/threadsafe_function_ex/threadsafe_function_ex_existing_tsfn.cc b/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc similarity index 96% rename from test/threadsafe_function_ex/threadsafe_function_ex_existing_tsfn.cc rename to test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc index fc28a06c5..799aacb9f 100644 --- a/test/threadsafe_function_ex/threadsafe_function_ex_existing_tsfn.cc +++ b/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc @@ -21,7 +21,7 @@ struct TestContext { }; }; -using TSFN = ThreadSafeFunctionEx; +using TSFN = TypedThreadSafeFunction; void FinalizeCB(napi_env env, void * /*finalizeData */, void *context) { TestContext *testContext = static_cast(context); @@ -104,7 +104,7 @@ static Value TestCall(const CallbackInfo &info) { } // namespace -Object InitThreadSafeFunctionExExistingTsfn(Env env) { +Object InitTypedThreadSafeFunctionExistingTsfn(Env env) { Object exports = Object::New(env); exports["testCall"] = Function::New(env, TestCall); diff --git a/test/threadsafe_function_ex/threadsafe_function_ex_existing_tsfn.js b/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js similarity index 89% rename from test/threadsafe_function_ex/threadsafe_function_ex_existing_tsfn.js rename to test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js index d42517d9f..b6df669d4 100644 --- a/test/threadsafe_function_ex/threadsafe_function_ex_existing_tsfn.js +++ b/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js @@ -8,8 +8,8 @@ module.exports = test(require(`../build/${buildType}/binding.node`)) .then(() => test(require(`../build/${buildType}/binding_noexcept.node`))); async function test(binding) { - const testCall = binding.threadsafe_function_ex_existing_tsfn.testCall; - + const testCall = binding.typed_threadsafe_function_existing_tsfn.testCall; + assert.strictEqual(typeof await testCall({ blocking: true, data: true }), "number"); assert.strictEqual(typeof await testCall({ blocking: true, data: false }), "undefined"); assert.strictEqual(typeof await testCall({ blocking: false, data: true }), "number"); diff --git a/test/threadsafe_function_ex/threadsafe_function_ex_ptr.cc b/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc similarity index 83% rename from test/threadsafe_function_ex/threadsafe_function_ex_ptr.cc rename to test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc index c8810ce50..27367e4ea 100644 --- a/test/threadsafe_function_ex/threadsafe_function_ex_ptr.cc +++ b/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc @@ -6,7 +6,7 @@ using namespace Napi; namespace { -using TSFN = ThreadSafeFunctionEx<>; +using TSFN = TypedThreadSafeFunction<>; static Value Test(const CallbackInfo& info) { Object resource = info[0].As(); @@ -18,7 +18,7 @@ static Value Test(const CallbackInfo& info) { } -Object InitThreadSafeFunctionExPtr(Env env) { +Object InitTypedThreadSafeFunctionPtr(Env env) { Object exports = Object::New(env); exports["test"] = Function::New(env, Test); diff --git a/test/threadsafe_function_ex/threadsafe_function_ex_ptr.js b/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js similarity index 79% rename from test/threadsafe_function_ex/threadsafe_function_ex_ptr.js rename to test/typed_threadsafe_function/typed_threadsafe_function_ptr.js index 1276d0930..47b187761 100644 --- a/test/threadsafe_function_ex/threadsafe_function_ex_ptr.js +++ b/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js @@ -6,5 +6,5 @@ test(require(`../build/${buildType}/binding.node`)); test(require(`../build/${buildType}/binding_noexcept.node`)); function test(binding) { - binding.threadsafe_function_ex_ptr.test({}, () => {}); + binding.typed_threadsafe_function_ptr.test({}, () => {}); } diff --git a/test/threadsafe_function_ex/threadsafe_function_ex_sum.cc b/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc similarity index 97% rename from test/threadsafe_function_ex/threadsafe_function_ex_sum.cc rename to test/typed_threadsafe_function/typed_threadsafe_function_sum.cc index 69c8a8fb2..6b33499a6 100644 --- a/test/threadsafe_function_ex/threadsafe_function_ex_sum.cc +++ b/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc @@ -37,10 +37,10 @@ struct TestData { delete data; } - ThreadSafeFunctionEx tsfn; + TypedThreadSafeFunction tsfn; }; -using TSFN = ThreadSafeFunctionEx; +using TSFN = TypedThreadSafeFunction; void FinalizerCallback(Napi::Env env, void *, TestData *finalizeData) { for (size_t i = 0; i < finalizeData->threads.size(); ++i) { @@ -209,7 +209,7 @@ static Value TestAcquire(const CallbackInfo &info) { } } // namespace -Object InitThreadSafeFunctionExSum(Env env) { +Object InitTypedThreadSafeFunctionSum(Env env) { Object exports = Object::New(env); exports["testDelayedTSFN"] = Function::New(env, TestDelayedTSFN); exports["testWithTSFN"] = Function::New(env, TestWithTSFN); diff --git a/test/threadsafe_function_ex/threadsafe_function_ex_sum.js b/test/typed_threadsafe_function/typed_threadsafe_function_sum.js similarity index 88% rename from test/threadsafe_function_ex/threadsafe_function_ex_sum.js rename to test/typed_threadsafe_function/typed_threadsafe_function_sum.js index ef7162c25..8f10476f6 100644 --- a/test/threadsafe_function_ex/threadsafe_function_ex_sum.js +++ b/test/typed_threadsafe_function/typed_threadsafe_function_sum.js @@ -45,7 +45,7 @@ function test(binding) { async function checkAcquire() { const calls = []; - const { promise, createThread, stopThreads } = binding.threadsafe_function_ex_sum.testAcquire(Array.prototype.push.bind(calls)); + const { promise, createThread, stopThreads } = binding.typed_threadsafe_function_sum.testAcquire(Array.prototype.push.bind(calls)); for (let i = 0; i < THREAD_COUNT; i++) { createThread(); } @@ -55,7 +55,7 @@ function test(binding) { assert.equal(sum(calls), EXPECTED_SUM); } - return check(binding.threadsafe_function_ex_sum.testDelayedTSFN) - .then(() => check(binding.threadsafe_function_ex_sum.testWithTSFN)) + return check(binding.typed_threadsafe_function_sum.testDelayedTSFN) + .then(() => check(binding.typed_threadsafe_function_sum.testWithTSFN)) .then(() => checkAcquire()); } diff --git a/test/threadsafe_function_ex/threadsafe_function_ex_unref.cc b/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc similarity index 91% rename from test/threadsafe_function_ex/threadsafe_function_ex_unref.cc rename to test/typed_threadsafe_function/typed_threadsafe_function_unref.cc index 2e2041380..3f81611fc 100644 --- a/test/threadsafe_function_ex/threadsafe_function_ex_unref.cc +++ b/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc @@ -6,7 +6,7 @@ using namespace Napi; namespace { -using TSFN = ThreadSafeFunctionEx<>; +using TSFN = TypedThreadSafeFunction<>; using ContextType = std::nullptr_t; using FinalizerDataType = void; static Value TestUnref(const CallbackInfo& info) { @@ -35,7 +35,7 @@ static Value TestUnref(const CallbackInfo& info) { } -Object InitThreadSafeFunctionExUnref(Env env) { +Object InitTypedThreadSafeFunctionUnref(Env env) { Object exports = Object::New(env); exports["testUnref"] = Function::New(env, TestUnref); return exports; diff --git a/test/threadsafe_function_ex/threadsafe_function_ex_unref.js b/test/typed_threadsafe_function/typed_threadsafe_function_unref.js similarity index 95% rename from test/threadsafe_function_ex/threadsafe_function_ex_unref.js rename to test/typed_threadsafe_function/typed_threadsafe_function_unref.js index eee3fcf8f..55b42a553 100644 --- a/test/threadsafe_function_ex/threadsafe_function_ex_unref.js +++ b/test/typed_threadsafe_function/typed_threadsafe_function_unref.js @@ -50,6 +50,6 @@ function test(bindingFile) { } else { // Child process const binding = require(bindingFile); - binding.threadsafe_function_ex_unref.testUnref({}, () => { }); + binding.typed_threadsafe_function_unref.testUnref({}, () => { }); } }