{"action":"opened","issue":{"url":"https://api.github.com/repos/nwjs/nw.js/issues/3289","labels_url":"https://api.github.com/repos/nwjs/nw.js/issues/3289/labels{/name}","comments_url":"https://api.github.com/repos/nwjs/nw.js/issues/3289/comments","events_url":"https://api.github.com/repos/nwjs/nw.js/issues/3289/events","html_url":"https://github.com/nwjs/nw.js/issues/3289","id":64050666,"number":3289,"title":"Asynchronous callbacks in native addons","user":{"login":"justinmchase","id":10974,"avatar_url":"https://avatars.githubusercontent.com/u/10974?v=3","gravatar_id":"","url":"https://api.github.com/users/justinmchase","html_url":"https://github.com/justinmchase","followers_url":"https://api.github.com/users/justinmchase/followers","following_url":"https://api.github.com/users/justinmchase/following{/other_user}","gists_url":"https://api.github.com/users/justinmchase/gists{/gist_id}","starred_url":"https://api.github.com/users/justinmchase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinmchase/subscriptions","organizations_url":"https://api.github.com/users/justinmchase/orgs","repos_url":"https://api.github.com/users/justinmchase/repos","events_url":"https://api.github.com/users/justinmchase/events{/privacy}","received_events_url":"https://api.github.com/users/justinmchase/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-24T17:12:41Z","updated_at":"2015-03-24T17:12:41Z","closed_at":null,"body":"We have some code that appears to run from iojs command line successfully but fails when run as a native addon in nw.js.\r\n\r\nOur native addon has a background thread that is using libuv to queue messages and call javascript callbacks in the right thread. Without going into too much detail, we are initializing our watcher like this:\r\n\r\n    uv_async_init(uv_default_loop(), &watcher, reinterpret_cast<uv_async_cb>(listener));\r\n\r\nFrom the background thread we are queueing messages and then calling:\r\n\r\n    uv_async_send(&watcher);\r\n\r\nIn our callback function we are then doing:\r\n\r\n    Isolate* isolate = Isolate::GetCurrent();\r\n    Local<Context> context = Context::New(isolate); // crashes nwjs with error code 0x800000003\r\n    Context::Scope context_scope(context);\r\n\r\nWe have verified that `isolate` is not null and that the thread id of the callback function is the same as the thread id from the initialization (the ui thread).\r\n\r\nWhat is the appropriate way to asynchronously call a callback from a native addon in nwjs? Should we be using `uv_default_loop()` for our init? Is there some other api we should be using?\r\n\r\nI can provide more detailed code upon request."}}