Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for worker_threads #4

Closed
wants to merge 2 commits into from
Closed
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: 2 additions & 2 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void ConstantsInit(v8::Local<v8::Object> exports) {
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(NodeRdKafkaBuildInFeatures)).ToLocalChecked()); // NOLINT
}

void Init(v8::Local<v8::Object> exports, v8::Local<v8::Value> m_, void* v_) {
void Init(v8::Local<v8::Object> exports) {
#if NODE_MAJOR_VERSION <= 9 || (NODE_MAJOR_VERSION == 10 && NODE_MINOR_VERSION <= 15)
AtExit(RdKafkaCleanup);
#else
Expand All @@ -91,4 +91,4 @@ void Init(v8::Local<v8::Object> exports, v8::Local<v8::Value> m_, void* v_) {
Nan::New(RdKafka::version_str().c_str()).ToLocalChecked());
}

NODE_MODULE(kafka, Init)
NAN_MODULE_WORKER_ENABLED(kafka, Init)
18 changes: 18 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,21 @@
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE.txt file for details.
*/

const worker = require('worker_threads');
const t = require('assert');

module.exports = {
'Node package': {
'should not throw an error when module is loaded inside a worker': function() {
t.doesNotThrow(function() {
new worker.Worker(`
const t = require('assert');
const { isMainThread } = require('worker_threads');
t.strictEqual(isMainThread, false);
require("./librdkafka.js");
`, { eval: true });
});
},
}
}