From 3116522e7c33c579bbb8ac0ee12c27ff3ff9825c Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Wed, 6 Jun 2012 21:19:14 +0400 Subject: [PATCH] child_process: spawn().ref() and spawn().unref() --- lib/child_process.js | 10 ++++++++++ src/handle_wrap.cc | 14 ++++++++++++-- src/handle_wrap.h | 1 + src/process_wrap.cc | 3 +++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index f79481dcfe2..3f9e69d25d0 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -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(); +}; diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 944631a3be6..ead7da1f747 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -50,8 +50,18 @@ void HandleWrap::Initialize(Handle 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 HandleWrap::Ref(const Arguments& args) { + HandleScope scope; + + UNWRAP(HandleWrap) + + uv_ref(wrap->handle__); + wrap->unref_ = false; + + return v8::Undefined(); +} + + Handle HandleWrap::Unref(const Arguments& args) { HandleScope scope; diff --git a/src/handle_wrap.h b/src/handle_wrap.h index 35853a01105..a358e812a50 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -50,6 +50,7 @@ class HandleWrap { public: static void Initialize(v8::Handle target); static v8::Handle Close(const v8::Arguments& args); + static v8::Handle Ref(const v8::Arguments& args); static v8::Handle Unref(const v8::Arguments& args); protected: diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 101d89b3fde..1dc3ce437e2 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -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()); }