Skip to content

Commit

Permalink
Added stop() method to java object.
Browse files Browse the repository at this point in the history
It breaks the internal indefinite loop and allows Node process to quit without SIGTERM.

 Solves bug joeferner#539 - The process refuses to quit.
  • Loading branch information
jjuzna committed May 18, 2022
1 parent ce4f251 commit 21d07ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void uvAsyncCb_dynamicProxyJsCall(uv_async_t *handle) {
Nan::SetPrototypeMethod(t, "getStaticFieldValue", getStaticFieldValue);
Nan::SetPrototypeMethod(t, "setStaticFieldValue", setStaticFieldValue);
Nan::SetPrototypeMethod(t, "instanceOf", instanceOf);
Nan::SetPrototypeMethod(t, "stop", stop);

Nan::Set(target, Nan::New<v8::String>("Java").ToLocalChecked(), Nan::GetFunction(t).ToLocalChecked());

Expand Down Expand Up @@ -1239,6 +1240,10 @@ NAN_METHOD(Java::instanceOf) {
info.GetReturnValue().Set(Nan::New<v8::Boolean>(res));
}

NAN_METHOD(Java::stop) {
uv_close((uv_handle_t *)&uvAsync_dynamicProxyJsCall, NULL);
}

template <typename T>
std::string to_string(T value) {
std::ostringstream os;
Expand Down
1 change: 1 addition & 0 deletions src/java.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Java : public Nan::ObjectWrap {
static NAN_METHOD(getStaticFieldValue);
static NAN_METHOD(setStaticFieldValue);
static NAN_METHOD(instanceOf);
static NAN_METHOD(stop);
static NAN_GETTER(AccessorProhibitsOverwritingGetter);
static NAN_SETTER(AccessorProhibitsOverwritingSetter);
v8::Local<v8::Value> ensureJvm();
Expand Down

0 comments on commit 21d07ad

Please sign in to comment.