Skip to content
Permalink
Browse files

process, feat: change process.run to async mode.

  • Loading branch information...
xicilion committed Jul 9, 2019
1 parent ce4af53 commit 75903b7fcec83ff8b89ff5e3a6c1206eb6f26a2e
Showing with 45 additions and 19 deletions.
  1. +20 −7 fibjs/include/ifs/process.h
  2. +23 −10 fibjs/src/process/process.cpp
  3. +2 −2 idl/zh-cn/process.idl
@@ -55,8 +55,8 @@ class process_base : public EventEmitter_base {
static result_t open(exlib::string command, v8::Local<v8::Object> opts, obj_ptr<SubProcess_base>& retVal);
static result_t start(exlib::string command, v8::Local<v8::Array> args, v8::Local<v8::Object> opts, obj_ptr<SubProcess_base>& retVal);
static result_t start(exlib::string command, v8::Local<v8::Object> opts, obj_ptr<SubProcess_base>& retVal);
static result_t run(exlib::string command, v8::Local<v8::Array> args, v8::Local<v8::Object> opts, int32_t& retVal);
static result_t run(exlib::string command, v8::Local<v8::Object> opts, int32_t& retVal);
static result_t run(exlib::string command, v8::Local<v8::Array> args, v8::Local<v8::Object> opts, int32_t& retVal, AsyncEvent* ac);
static result_t run(exlib::string command, v8::Local<v8::Object> opts, int32_t& retVal, AsyncEvent* ac);

public:
static void s__new(const v8::FunctionCallbackInfo<v8::Value>& args)
@@ -95,6 +95,10 @@ class process_base : public EventEmitter_base {
static void s_open(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_start(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_run(const v8::FunctionCallbackInfo<v8::Value>& args);

public:
ASYNC_STATICVALUE4(process_base, run, exlib::string, v8::Local<v8::Array>, v8::Local<v8::Object>, int32_t);
ASYNC_STATICVALUE3(process_base, run, exlib::string, v8::Local<v8::Object>, int32_t);
};
}

@@ -115,7 +119,8 @@ inline ClassInfo& process_base::class_info()
{ "nextTick", s_nextTick, true },
{ "open", s_open, true },
{ "start", s_start, true },
{ "run", s_run, true }
{ "run", s_run, true },
{ "runSync", s_run, true }
};

static ClassData::ClassProperty s_property[] = {
@@ -499,20 +504,28 @@ inline void process_base::s_run(const v8::FunctionCallbackInfo<v8::Value>& args)
METHOD_NAME("process.run");
METHOD_ENTER();

METHOD_OVER(3, 2);
ASYNC_METHOD_OVER(3, 2);

ARG(exlib::string, 0);
ARG(v8::Local<v8::Array>, 1);
OPT_ARG(v8::Local<v8::Object>, 2, v8::Object::New(isolate));

hr = run(v0, v1, v2, vr);
if (!cb.IsEmpty()) {
acb_run(v0, v1, v2, cb);
hr = CALL_RETURN_NULL;
} else
hr = ac_run(v0, v1, v2, vr);

METHOD_OVER(2, 1);
ASYNC_METHOD_OVER(2, 1);

ARG(exlib::string, 0);
OPT_ARG(v8::Local<v8::Object>, 1, v8::Object::New(isolate));

hr = run(v0, v1, vr);
if (!cb.IsEmpty()) {
acb_run(v0, v1, cb);
hr = CALL_RETURN_NULL;
} else
hr = ac_run(v0, v1, vr);

METHOD_RETURN();
}
@@ -351,24 +351,37 @@ result_t process_base::start(exlib::string command, v8::Local<v8::Object> opts,
}

result_t process_base::run(exlib::string command, v8::Local<v8::Array> args,
v8::Local<v8::Object> opts, int32_t& retVal)
v8::Local<v8::Object> opts, int32_t& retVal, AsyncEvent* ac)
{
result_t hr;
obj_ptr<SubProcess_base> _sub;

hr = SubProcess::create(command, args, opts, false, _sub);
if (hr < 0)
return hr;
if (ac->isSync()) {
result_t hr;

return _sub->ac_wait(retVal);
hr = SubProcess::create(command, args, opts, false, _sub);
if (hr < 0)
return hr;

ac->m_ctx.resize(1);
ac->m_ctx[0] = _sub;

return CHECK_ERROR(CALL_E_NOSYNC);
}

_sub = SubProcess_base::getInstance(ac->m_ctx[0].object());
return _sub->wait(retVal, ac);
}

result_t process_base::run(exlib::string command, v8::Local<v8::Object> opts,
int32_t& retVal)
int32_t& retVal, AsyncEvent* ac)
{
Isolate* isolate = Isolate::current();
v8::Local<v8::Array> args = v8::Array::New(isolate->m_isolate);
v8::Local<v8::Array> args;

if (ac->isSync()) {
Isolate* isolate = Isolate::current();
args = v8::Array::New(isolate->m_isolate);
}

return run(command, args, opts, retVal);
return run(command, args, opts, retVal, ac);
}
}
@@ -227,7 +227,7 @@ module process : EventEmitter
@param opts 指定运行的选项
@return 返回命令的运行结果
*/
static Integer run(String command, Array args, Object opts = {});
static Integer run(String command, Array args, Object opts = {}) async;

/*! @brief 运行指定的命令行,并返回进程的结束代码

@@ -242,5 +242,5 @@ module process : EventEmitter
@param opts 指定运行的选项
@return 返回命令的运行结果
*/
static Integer run(String command, Object opts = {});
static Integer run(String command, Object opts = {}) async;
};

0 comments on commit 75903b7

Please sign in to comment.
You can’t perform that action at this time.