Skip to content

Instantly share code, notes, and snippets.

@gzmask
Created April 8, 2011 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gzmask/910349 to your computer and use it in GitHub Desktop.
Save gzmask/910349 to your computer and use it in GitHub Desktop.
// this function happens on the thread pool
// doing v8 things in here will make bad happen.
static int DoSomething (eio_req *req) {
struct simple_request * sr = (struct simple_request *)req->data;
//sleep(2); // just to make it less pointless to be async.
//req->result = sr->x + sr->y;
req->result = bayesian_test(sr->x, sr->y, sr->name);
return 0;
}
static int DoSomething_After (eio_req *req) {
HandleScope scope;
ev_unref(EV_DEFAULT_UC);
struct simple_request * sr = (struct simple_request *)req->data;
Local<Value> argv[3];
argv[0] = Local<Value>::New(Null()); //cb(er)
argv[1] = String::New(req->result); //cb(res)
argv[2] = String::New(sr->name); //cb(n)
TryCatch try_catch;
sr->cb->Call(Context::GetCurrent()->Global(), 3, argv);
if (try_catch.HasCaught()) {
FatalException(try_catch);
}
sr->cb.Dispose();
free(sr);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment