Created
April 8, 2011 17:44
-
-
Save gzmask/910349 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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