javascript - uv_queue_work does not run callback_method in node addon (c++) -


i making node addon in c++, , want able make callbacks other threads. try it, i'm making following test using uv_queue_work , nan. if call function hello, should start new thread method firstmethod, , when finishes, call next method "callbackmethod" in thread, make callback javascript. reason, runs first method , not run second.

this code.

void hello(const v8::functioncallbackinfo<v8::value>& args) {     v8::isolate* isolate = v8::isolate::getcurrent();     v8::handlescope scope(isolate);     v8::local<v8::function> callback;      callback = args[0].as<v8::function>();      listbaton* baton = new listbaton();     baton->callback = new nan::callback(callback);      uv_work_t* req = new uv_work_t();     req->data = baton;     uv_queue_work(uv_default_loop(), req, firstmethod, callbackmethod); }  void firstmethod(uv_work_t* req) {     std::cout << "entering pre thread" << std::endl;     sleep(1);     std::cout << "leaving pre thread" << std::endl; }  void callbackmethod(uv_work_t* req, int status) {     v8::isolate* isolate = v8::isolate::getcurrent();     v8::handlescope scope(isolate);     if(!isolate)     {         std::cout << "isolate null" << std::endl;         isolate = v8::isolate::new();         isolate->enter();     }     listbaton* data = static_cast<listbaton*>(req->data);      v8::local<v8::value> argv[2] = {             v8::undefined(isolate),             v8::string::newfromutf8(isolate,"world")     };       std::cout << "sending callback" << std::endl;     data->callback->call(2,argv); } void init (v8::handle<v8::object> target) {     node_set_method(target, "hello", hello); }  node_module(hellonan, init); 

if guys me appreciate lot...

if actual try follow instead of data->callback->call(2,argv);

// execute callback local<function>::new(isolate, data->callback)->call(isolate->getcurrentcontext()->global(), 2, argv);  // free persistent function callback data->callback.reset();  delete data; 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -