我是 nodeJS 和节点扩展的新手。我正在为 Node js 编写一个本机扩展,它将接收虚拟函数 OnEvent(param1, param2, param3) 的回调。代码如下:
bool MyExt::OnEvent(int eventType, string param1, string param2)
{
printf("MyExt:: onevent___ \n");
{
//// Crashes here, but if I use Locker, it get stuck!!!!!!
//Locker l;
Local<Value> argv[3] = {
Local<Value>::New(Integer::New(1)),
Local<Value>::New(String::New("parameter 1")),
Local<String>::New(String::New("parameter 2"))
};
TryCatch try_catch;
//// I need to call this
m_EventCallback->Call(Context::GetCurrent()->Global(), 3, argv);
if (try_catch.HasCaught()){
printf("Callback is Exception() \n");
}
printf("Callback is IsCallable() \n");
}
return true;
}
我需要使用 m_EventCallback 将此回调参数转发到服务器脚本。函数 bool OnEvent 是从不同的线程调用的。
我尝试使用 uv_async_send 但未能成功。
任何帮助或指导将不胜感激。
使用 uv_async_send 是正确的方法:
- 在“主”线程上调用 uv_async_init。
- 然后从您的工作人员中调用 uv_async_send 。
- 不要忘记 uv_close 回到 main 上。
http://nikhilm.github.com/uvbook/threads.html http://nikhilm.github.com/uvbook/threads.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)