Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

child_process: spawn().ref() and spawn().unref() #3381

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/child_process.js
Expand Up @@ -845,3 +845,13 @@ ChildProcess.prototype.kill = function(sig) {
}
}
};


ChildProcess.prototype.ref = function() {
this._handle.ref();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (this._handle) this._handle.ref();

};


ChildProcess.prototype.unref = function() {
this._handle.unref();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

};
14 changes: 12 additions & 2 deletions src/handle_wrap.cc
Expand Up @@ -50,8 +50,18 @@ void HandleWrap::Initialize(Handle<Object> target) {
}


// This function is used only for process.stdout. It's put here instead of
// in TTYWrap because here we have access to the Close binding.
Handle<Value> HandleWrap::Ref(const Arguments& args) {
HandleScope scope;

UNWRAP(HandleWrap)

uv_ref(wrap->handle__);
wrap->unref_ = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no real need to track the unref state, uv_ref() and uv_unref() are idempotent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This state is used later in node.cc to check if handle is reffed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, you're right. Guess who wrote that code, then promptly forgot about it? :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I think that this code is a point for later rewrite anyway :) Probably, I'll make things derived HandleWraps more DRY for 0.9


return v8::Undefined();
}


Handle<Value> HandleWrap::Unref(const Arguments& args) {
HandleScope scope;

Expand Down
1 change: 1 addition & 0 deletions src/handle_wrap.h
Expand Up @@ -50,6 +50,7 @@ class HandleWrap {
public:
static void Initialize(v8::Handle<v8::Object> target);
static v8::Handle<v8::Value> Close(const v8::Arguments& args);
static v8::Handle<v8::Value> Ref(const v8::Arguments& args);
static v8::Handle<v8::Value> Unref(const v8::Arguments& args);

protected:
Expand Down
3 changes: 3 additions & 0 deletions src/process_wrap.cc
Expand Up @@ -67,6 +67,9 @@ class ProcessWrap : public HandleWrap {
NODE_SET_PROTOTYPE_METHOD(constructor, "spawn", Spawn);
NODE_SET_PROTOTYPE_METHOD(constructor, "kill", Kill);

NODE_SET_PROTOTYPE_METHOD(constructor, "ref", HandleWrap::Ref);
NODE_SET_PROTOTYPE_METHOD(constructor, "unref", HandleWrap::Unref);

target->Set(String::NewSymbol("Process"), constructor->GetFunction());
}

Expand Down
3 changes: 3 additions & 0 deletions src/timer_wrap.cc
Expand Up @@ -59,6 +59,9 @@ class TimerWrap : public HandleWrap {
NODE_SET_PROTOTYPE_METHOD(constructor, "getRepeat", GetRepeat);
NODE_SET_PROTOTYPE_METHOD(constructor, "again", Again);

NODE_SET_PROTOTYPE_METHOD(constructor, "ref", HandleWrap::Ref);
NODE_SET_PROTOTYPE_METHOD(constructor, "unref", HandleWrap::Unref);

ontimeout_sym = NODE_PSYMBOL("ontimeout");

target->Set(String::NewSymbol("Timer"), constructor->GetFunction());
Expand Down