@@ -2249,15 +2249,14 @@ namespace Napi {
2249
2249
napi_threadsafe_function _tsfn;
2250
2250
};
2251
2251
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>
2257
2258
class TypedThreadSafeFunction {
2258
-
2259
- public:
2260
-
2259
+ public:
2261
2260
// This API may only be called from the main thread.
2262
2261
// Helper function that returns nullptr if running N-API 5+, otherwise a
2263
2262
// non-empty, no-op Function. This provides the ability to specify at
@@ -2268,85 +2267,123 @@ namespace Napi {
2268
2267
#else
2269
2268
static Napi::Function EmptyFunctionFactory (Napi::Env env);
2270
2269
#endif
2271
- static Napi::Function FunctionOrEmpty (Napi::Env env, Napi::Function& callback);
2270
+ static Napi::Function FunctionOrEmpty (Napi::Env env,
2271
+ Napi::Function& callback);
2272
2272
2273
2273
#if NAPI_VERSION > 4
2274
2274
// This API may only be called from the main thread.
2275
2275
// Creates a new threadsafe function with:
2276
2276
// Callback [missing] Resource [missing] Finalizer [missing]
2277
2277
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 );
2281
2284
2282
2285
// This API may only be called from the main thread.
2283
2286
// Creates a new threadsafe function with:
2284
2287
// Callback [missing] Resource [passed] Finalizer [missing]
2285
2288
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 );
2290
2296
2291
2297
// This API may only be called from the main thread.
2292
2298
// Creates a new threadsafe function with:
2293
2299
// Callback [missing] Resource [missing] Finalizer [passed]
2294
- template <typename ResourceString, typename Finalizer,
2300
+ template <typename ResourceString,
2301
+ typename Finalizer,
2295
2302
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 );
2300
2311
2301
2312
// This API may only be called from the main thread.
2302
2313
// Creates a new threadsafe function with:
2303
2314
// Callback [missing] Resource [passed] Finalizer [passed]
2304
- template <typename ResourceString, typename Finalizer,
2315
+ template <typename ResourceString,
2316
+ typename Finalizer,
2305
2317
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 );
2310
2327
#endif
2311
2328
2312
2329
// This API may only be called from the main thread.
2313
2330
// Creates a new threadsafe function with:
2314
2331
// Callback [passed] Resource [missing] Finalizer [missing]
2315
2332
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 );
2320
2340
2321
2341
// This API may only be called from the main thread.
2322
2342
// Creates a new threadsafe function with:
2323
2343
// Callback [passed] Resource [passed] Finalizer [missing]
2324
2344
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 );
2329
2353
2330
2354
// This API may only be called from the main thread.
2331
2355
// Creates a new threadsafe function with:
2332
2356
// Callback [passed] Resource [missing] Finalizer [passed]
2333
- template <typename ResourceString, typename Finalizer,
2357
+ template <typename ResourceString,
2358
+ typename Finalizer,
2334
2359
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 );
2339
2369
2340
2370
// This API may only be called from the main thread.
2341
2371
// Creates a new threadsafe function with:
2342
2372
// 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 );
2350
2387
2351
2388
TypedThreadSafeFunction<ContextType, DataType, CallJs>();
2352
2389
TypedThreadSafeFunction<ContextType, DataType, CallJs>(
@@ -2355,10 +2392,10 @@ namespace Napi {
2355
2392
operator napi_threadsafe_function () const ;
2356
2393
2357
2394
// This API may be called from any thread.
2358
- napi_status BlockingCall (DataType * data = nullptr ) const ;
2395
+ napi_status BlockingCall (DataType* data = nullptr ) const ;
2359
2396
2360
2397
// This API may be called from any thread.
2361
- napi_status NonBlockingCall (DataType * data = nullptr ) const ;
2398
+ napi_status NonBlockingCall (DataType* data = nullptr ) const ;
2362
2399
2363
2400
// This API may only be called from the main thread.
2364
2401
void Ref (napi_env env) const ;
@@ -2376,22 +2413,30 @@ namespace Napi {
2376
2413
napi_status Abort ();
2377
2414
2378
2415
// This API may be called from any thread.
2379
- ContextType * GetContext () const ;
2416
+ ContextType* GetContext () const ;
2380
2417
2381
- private:
2382
- template <typename ResourceString, typename Finalizer,
2418
+ private:
2419
+ template <typename ResourceString,
2420
+ typename Finalizer,
2383
2421
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,
2389
2432
napi_finalize wrapper);
2390
2433
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);
2393
2438
2394
- protected:
2439
+ protected:
2395
2440
napi_threadsafe_function _tsfn;
2396
2441
};
2397
2442
template <typename DataType>
0 commit comments