Commit cbd74f7c by Konstantin Käfer

add wait() method that waits until the queue is empty

parent df47114b
{ {
"name": "sqlite3", "name": "sqlite3",
"description": "Asynchronous, non-blocking SQLite3 bindings", "description": "Asynchronous, non-blocking SQLite3 bindings",
"version": "2.1.6", "version": "2.1.7-alpha",
"homepage": "http://github.com/developmentseed/node-sqlite3", "homepage": "http://github.com/developmentseed/node-sqlite3",
"author": { "author": {
"name": "Development Seed", "name": "Development Seed",
......
...@@ -20,6 +20,7 @@ void Database::Init(Handle<Object> target) { ...@@ -20,6 +20,7 @@ void Database::Init(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", Close); NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", Close);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "exec", Exec); NODE_SET_PROTOTYPE_METHOD(constructor_template, "exec", Exec);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "wait", Wait);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "loadExtension", LoadExtension); NODE_SET_PROTOTYPE_METHOD(constructor_template, "loadExtension", LoadExtension);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "serialize", Serialize); NODE_SET_PROTOTYPE_METHOD(constructor_template, "serialize", Serialize);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "parallelize", Parallelize); NODE_SET_PROTOTYPE_METHOD(constructor_template, "parallelize", Parallelize);
...@@ -550,6 +551,36 @@ void Database::Work_AfterExec(uv_work_t* req) { ...@@ -550,6 +551,36 @@ void Database::Work_AfterExec(uv_work_t* req) {
delete baton; delete baton;
} }
Handle<Value> Database::Wait(const Arguments& args) {
HandleScope scope;
Database* db = ObjectWrap::Unwrap<Database>(args.This());
OPTIONAL_ARGUMENT_FUNCTION(0, callback);
Baton* baton = new Baton(db, callback);
db->Schedule(Work_Wait, baton, true);
return args.This();
}
void Database::Work_Wait(Baton* baton) {
HandleScope scope;
assert(baton->db->locked);
assert(baton->db->open);
assert(baton->db->handle);
assert(baton->db->pending == 0);
if (!baton->callback.IsEmpty() && baton->callback->IsFunction()) {
Local<Value> argv[] = { Local<Value>::New(Null()) };
TRY_CATCH_CALL(baton->db->handle_, baton->callback, 1, argv);
}
baton->db->Process();
delete baton;
}
Handle<Value> Database::LoadExtension(const Arguments& args) { Handle<Value> Database::LoadExtension(const Arguments& args) {
HandleScope scope; HandleScope scope;
Database* db = ObjectWrap::Unwrap<Database>(args.This()); Database* db = ObjectWrap::Unwrap<Database>(args.This());
......
...@@ -131,6 +131,9 @@ protected: ...@@ -131,6 +131,9 @@ protected:
static void Work_Exec(uv_work_t* req); static void Work_Exec(uv_work_t* req);
static void Work_AfterExec(uv_work_t* req); static void Work_AfterExec(uv_work_t* req);
static Handle<Value> Wait(const Arguments& args);
static void Work_Wait(Baton* baton);
static Handle<Value> Close(const Arguments& args); static Handle<Value> Close(const Arguments& args);
static void Work_BeginClose(Baton* baton); static void Work_BeginClose(Baton* baton);
static void Work_Close(uv_work_t* req); static void Work_Close(uv_work_t* req);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment