paddybyers/anode — Issue #7: Thread pooling not working in libuv, calling uv_run(uv_default_loop()) fixes
Author: skabbes
Created: 2012-01-24 04:25:36+00:00
State: open

When compiling [node-sqlite3](https://github.com/developmentseed/node-sqlite3) for anode, db connections weren't being successfully opened. Investigating further, it seemed that the the "after" callback in `uv_queue_work` wasn't being called. Adding `uv_run(uv_default_loop())` fixes both this test code **and** the sqlite code.

This code shows the error:

```c++

#include
#include
#include

#define APPNAME "HELLOWORLD"

using namespace v8;

static int timesFinished = 0;

void AsyncWork(uv_work_t* req) {
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "In Async Work");
timesFinished++;
}

void AfterAsync(uv_work_t* req) {
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Finished Async Work");
timesFinished++;

// be nice and clean up
delete req;
req = NULL;
}

Handle Method(const Arguments& args) {
HandleScope scope;

uv_work_t * req = new uv_work_t();
int status = uv_queue_work(uv_default_loop(), req, AsyncWork, AfterAsync);
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "uv_queue_work status %d", status);

// I Shouldn't have to call this... but calling it fixes this code AND SQLITE3
uv_run(uv_default_loop());

__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "work count should be 2 %d", timesFinished);

return scope.Close(String::New("something worked"));
}

void init(Handle