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

Commit

Permalink
child_process: spawn().ref() and spawn().unref()
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Jun 7, 2012
1 parent c45522d commit 3116522
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
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() {
if (this._handle) this._handle.ref();
};


ChildProcess.prototype.unref = function() {
if (this._handle) this._handle.unref();
};
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;

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

0 comments on commit 3116522

Please sign in to comment.