@@ -2249,15 +2249,14 @@ namespace Napi {
22492249 napi_threadsafe_function _tsfn;
22502250 };
22512251
2252- // A TypedThreadSafeFunction by default has no context (nullptr) and can accept
2253- // any type (void) to its CallJs.
2254- template <typename ContextType = std::nullptr_t , typename DataType = void ,
2255- void (*CallJs)(Napi::Env, Napi::Function, ContextType *,
2256- DataType *) = nullptr>
2252+ // A TypedThreadSafeFunction by default has no context (nullptr) and can
2253+ // accept any type (void) to its CallJs.
2254+ template <typename ContextType = std::nullptr_t ,
2255+ typename DataType = void ,
2256+ void (*CallJs)(Napi::Env, Napi::Function, ContextType*, DataType*) =
2257+ nullptr>
22572258 class TypedThreadSafeFunction {
2258-
2259- public:
2260-
2259+ public:
22612260 // This API may only be called from the main thread.
22622261 // Helper function that returns nullptr if running N-API 5+, otherwise a
22632262 // non-empty, no-op Function. This provides the ability to specify at
@@ -2268,85 +2267,123 @@ namespace Napi {
22682267#else
22692268 static Napi::Function EmptyFunctionFactory (Napi::Env env);
22702269#endif
2271- static Napi::Function FunctionOrEmpty (Napi::Env env, Napi::Function& callback);
2270+ static Napi::Function FunctionOrEmpty (Napi::Env env,
2271+ Napi::Function& callback);
22722272
22732273#if NAPI_VERSION > 4
22742274 // This API may only be called from the main thread.
22752275 // Creates a new threadsafe function with:
22762276 // Callback [missing] Resource [missing] Finalizer [missing]
22772277 template <typename ResourceString>
2278- static TypedThreadSafeFunction<ContextType, DataType, CallJs>
2279- New (napi_env env, ResourceString resourceName, size_t maxQueueSize,
2280- size_t initialThreadCount, ContextType *context = nullptr );
2278+ static TypedThreadSafeFunction<ContextType, DataType, CallJs> New (
2279+ napi_env env,
2280+ ResourceString resourceName,
2281+ size_t maxQueueSize,
2282+ size_t initialThreadCount,
2283+ ContextType* context = nullptr );
22812284
22822285 // This API may only be called from the main thread.
22832286 // Creates a new threadsafe function with:
22842287 // Callback [missing] Resource [passed] Finalizer [missing]
22852288 template <typename ResourceString>
2286- static TypedThreadSafeFunction<ContextType, DataType, CallJs>
2287- New (napi_env env, const Object &resource, ResourceString resourceName,
2288- size_t maxQueueSize, size_t initialThreadCount,
2289- ContextType *context = nullptr );
2289+ static TypedThreadSafeFunction<ContextType, DataType, CallJs> New (
2290+ napi_env env,
2291+ const Object& resource,
2292+ ResourceString resourceName,
2293+ size_t maxQueueSize,
2294+ size_t initialThreadCount,
2295+ ContextType* context = nullptr );
22902296
22912297 // This API may only be called from the main thread.
22922298 // Creates a new threadsafe function with:
22932299 // Callback [missing] Resource [missing] Finalizer [passed]
2294- template <typename ResourceString, typename Finalizer,
2300+ template <typename ResourceString,
2301+ typename Finalizer,
22952302 typename FinalizerDataType = void >
2296- static TypedThreadSafeFunction<ContextType, DataType, CallJs>
2297- New (napi_env env, ResourceString resourceName, size_t maxQueueSize,
2298- size_t initialThreadCount, ContextType *context,
2299- Finalizer finalizeCallback, FinalizerDataType *data = nullptr );
2303+ static TypedThreadSafeFunction<ContextType, DataType, CallJs> New (
2304+ napi_env env,
2305+ ResourceString resourceName,
2306+ size_t maxQueueSize,
2307+ size_t initialThreadCount,
2308+ ContextType* context,
2309+ Finalizer finalizeCallback,
2310+ FinalizerDataType* data = nullptr );
23002311
23012312 // This API may only be called from the main thread.
23022313 // Creates a new threadsafe function with:
23032314 // Callback [missing] Resource [passed] Finalizer [passed]
2304- template <typename ResourceString, typename Finalizer,
2315+ template <typename ResourceString,
2316+ typename Finalizer,
23052317 typename FinalizerDataType = void >
2306- static TypedThreadSafeFunction<ContextType, DataType, CallJs>
2307- New (napi_env env, const Object &resource, ResourceString resourceName,
2308- size_t maxQueueSize, size_t initialThreadCount, ContextType *context,
2309- Finalizer finalizeCallback, FinalizerDataType *data = nullptr );
2318+ static TypedThreadSafeFunction<ContextType, DataType, CallJs> New (
2319+ napi_env env,
2320+ const Object& resource,
2321+ ResourceString resourceName,
2322+ size_t maxQueueSize,
2323+ size_t initialThreadCount,
2324+ ContextType* context,
2325+ Finalizer finalizeCallback,
2326+ FinalizerDataType* data = nullptr );
23102327#endif
23112328
23122329 // This API may only be called from the main thread.
23132330 // Creates a new threadsafe function with:
23142331 // Callback [passed] Resource [missing] Finalizer [missing]
23152332 template <typename ResourceString>
2316- static TypedThreadSafeFunction<ContextType, DataType, CallJs>
2317- New (napi_env env, const Function &callback, ResourceString resourceName,
2318- size_t maxQueueSize, size_t initialThreadCount,
2319- ContextType *context = nullptr );
2333+ static TypedThreadSafeFunction<ContextType, DataType, CallJs> New (
2334+ napi_env env,
2335+ const Function& callback,
2336+ ResourceString resourceName,
2337+ size_t maxQueueSize,
2338+ size_t initialThreadCount,
2339+ ContextType* context = nullptr );
23202340
23212341 // This API may only be called from the main thread.
23222342 // Creates a new threadsafe function with:
23232343 // Callback [passed] Resource [passed] Finalizer [missing]
23242344 template <typename ResourceString>
2325- static TypedThreadSafeFunction<ContextType, DataType, CallJs>
2326- New (napi_env env, const Function &callback, const Object &resource,
2327- ResourceString resourceName, size_t maxQueueSize,
2328- size_t initialThreadCount, ContextType *context = nullptr );
2345+ static TypedThreadSafeFunction<ContextType, DataType, CallJs> New (
2346+ napi_env env,
2347+ const Function& callback,
2348+ const Object& resource,
2349+ ResourceString resourceName,
2350+ size_t maxQueueSize,
2351+ size_t initialThreadCount,
2352+ ContextType* context = nullptr );
23292353
23302354 // This API may only be called from the main thread.
23312355 // Creates a new threadsafe function with:
23322356 // Callback [passed] Resource [missing] Finalizer [passed]
2333- template <typename ResourceString, typename Finalizer,
2357+ template <typename ResourceString,
2358+ typename Finalizer,
23342359 typename FinalizerDataType = void >
2335- static TypedThreadSafeFunction<ContextType, DataType, CallJs>
2336- New (napi_env env, const Function &callback, ResourceString resourceName,
2337- size_t maxQueueSize, size_t initialThreadCount, ContextType *context,
2338- Finalizer finalizeCallback, FinalizerDataType *data = nullptr );
2360+ static TypedThreadSafeFunction<ContextType, DataType, CallJs> New (
2361+ napi_env env,
2362+ const Function& callback,
2363+ ResourceString resourceName,
2364+ size_t maxQueueSize,
2365+ size_t initialThreadCount,
2366+ ContextType* context,
2367+ Finalizer finalizeCallback,
2368+ FinalizerDataType* data = nullptr );
23392369
23402370 // This API may only be called from the main thread.
23412371 // Creates a new threadsafe function with:
23422372 // Callback [passed] Resource [passed] Finalizer [passed]
2343- template <typename CallbackType, typename ResourceString, typename Finalizer,
2344- typename FinalizerDataType>
2345- static TypedThreadSafeFunction<ContextType, DataType, CallJs>
2346- New (napi_env env, CallbackType callback, const Object &resource,
2347- ResourceString resourceName, size_t maxQueueSize,
2348- size_t initialThreadCount, ContextType *context,
2349- Finalizer finalizeCallback, FinalizerDataType *data = nullptr );
2373+ template <typename CallbackType,
2374+ typename ResourceString,
2375+ typename Finalizer,
2376+ typename FinalizerDataType>
2377+ static TypedThreadSafeFunction<ContextType, DataType, CallJs> New (
2378+ napi_env env,
2379+ CallbackType callback,
2380+ const Object& resource,
2381+ ResourceString resourceName,
2382+ size_t maxQueueSize,
2383+ size_t initialThreadCount,
2384+ ContextType* context,
2385+ Finalizer finalizeCallback,
2386+ FinalizerDataType* data = nullptr );
23502387
23512388 TypedThreadSafeFunction<ContextType, DataType, CallJs>();
23522389 TypedThreadSafeFunction<ContextType, DataType, CallJs>(
@@ -2355,10 +2392,10 @@ namespace Napi {
23552392 operator napi_threadsafe_function () const ;
23562393
23572394 // This API may be called from any thread.
2358- napi_status BlockingCall (DataType * data = nullptr ) const ;
2395+ napi_status BlockingCall (DataType* data = nullptr ) const ;
23592396
23602397 // This API may be called from any thread.
2361- napi_status NonBlockingCall (DataType * data = nullptr ) const ;
2398+ napi_status NonBlockingCall (DataType* data = nullptr ) const ;
23622399
23632400 // This API may only be called from the main thread.
23642401 void Ref (napi_env env) const ;
@@ -2376,22 +2413,30 @@ namespace Napi {
23762413 napi_status Abort ();
23772414
23782415 // This API may be called from any thread.
2379- ContextType * GetContext () const ;
2416+ ContextType* GetContext () const ;
23802417
2381- private:
2382- template <typename ResourceString, typename Finalizer,
2418+ private:
2419+ template <typename ResourceString,
2420+ typename Finalizer,
23832421 typename FinalizerDataType>
2384- static TypedThreadSafeFunction<ContextType, DataType, CallJs>
2385- New (napi_env env, const Function &callback, const Object &resource,
2386- ResourceString resourceName, size_t maxQueueSize,
2387- size_t initialThreadCount, ContextType *context,
2388- Finalizer finalizeCallback, FinalizerDataType *data,
2422+ static TypedThreadSafeFunction<ContextType, DataType, CallJs> New (
2423+ napi_env env,
2424+ const Function& callback,
2425+ const Object& resource,
2426+ ResourceString resourceName,
2427+ size_t maxQueueSize,
2428+ size_t initialThreadCount,
2429+ ContextType* context,
2430+ Finalizer finalizeCallback,
2431+ FinalizerDataType* data,
23892432 napi_finalize wrapper);
23902433
2391- static void CallJsInternal (napi_env env, napi_value jsCallback,
2392- void *context, void *data);
2434+ static void CallJsInternal (napi_env env,
2435+ napi_value jsCallback,
2436+ void * context,
2437+ void * data);
23932438
2394- protected:
2439+ protected:
23952440 napi_threadsafe_function _tsfn;
23962441 };
23972442 template <typename DataType>
0 commit comments