Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ struct FinalizeData {
Hint* hint;
};

#if (NAPI_VERSION > 3)
template <typename ContextType=void,
typename Finalizer=std::function<void(Env, void*, ContextType*)>,
typename FinalizerDataType=void>
Expand Down Expand Up @@ -196,6 +197,7 @@ struct ThreadSafeFinalize {
Finalizer callback;
napi_threadsafe_function* tsfn;
};
#endif

template <typename Getter, typename Setter>
struct AccessorCallbackData {
Expand Down Expand Up @@ -3740,6 +3742,7 @@ inline void AsyncWorker::OnWorkComplete(
}
}

#if (NAPI_VERSION > 3)
////////////////////////////////////////////////////////////////////////////////
// ThreadSafeFunction class
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -4058,6 +4061,7 @@ inline void ThreadSafeFunction::CallJS(napi_env env,
Function(env, jsCallback).Call({});
}
}
#endif

////////////////////////////////////////////////////////////////////////////////
// Memory Management class
Expand Down
2 changes: 2 additions & 0 deletions napi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,7 @@ namespace Napi {
bool _suppress_destruct;
};

#if (NAPI_VERSION > 3)
class ThreadSafeFunction {
public:
// This API may only be called from the main thread.
Expand Down Expand Up @@ -2029,6 +2030,7 @@ namespace Napi {

std::unique_ptr<napi_threadsafe_function> _tsfn;
};
#endif

// Memory management.
class MemoryManagement {
Expand Down
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ if ((process.env.npm_config_NAPI_VERSION !== undefined) &&
testModules.splice(testModules.indexOf('version_management'), 1);
}

if ((process.env.npm_config_NAPI_VERSION !== undefined) &&
(process.env.npm_config_NAPI_VERSION < 4)) {
testModules.splice(testModules.indexOf('threadsafe_function/threadsafe_function'), 1);
}

if (typeof global.gc === 'function') {
console.log('Starting test suite\n');

Expand Down
4 changes: 4 additions & 0 deletions test/threadsafe_function/threadsafe_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <thread>
#include "napi.h"

#if (NAPI_VERSION > 3)

using namespace Napi;

constexpr size_t ARRAY_LENGTH = 10;
Expand Down Expand Up @@ -177,3 +179,5 @@ Object InitThreadSafeFunction(Env env) {

return exports;
}

#endif