Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cbd74f7

Browse filesBrowse files
committed
add wait() method that waits until the queue is empty
1 parent df47114 commit cbd74f7
Copy full SHA for cbd74f7

3 files changed

+35-1Lines changed: 35 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sqlite3",
33
"description": "Asynchronous, non-blocking SQLite3 bindings",
4-
"version": "2.1.6",
4+
"version": "2.1.7-alpha",
55
"homepage": "http://github.com/developmentseed/node-sqlite3",
66
"author": {
77
"name": "Development Seed",
Collapse file

‎src/database.cc‎

Copy file name to clipboardExpand all lines: src/database.cc
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void Database::Init(Handle<Object> target) {
2020

2121
NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", Close);
2222
NODE_SET_PROTOTYPE_METHOD(constructor_template, "exec", Exec);
23+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "wait", Wait);
2324
NODE_SET_PROTOTYPE_METHOD(constructor_template, "loadExtension", LoadExtension);
2425
NODE_SET_PROTOTYPE_METHOD(constructor_template, "serialize", Serialize);
2526
NODE_SET_PROTOTYPE_METHOD(constructor_template, "parallelize", Parallelize);
@@ -550,6 +551,36 @@ void Database::Work_AfterExec(uv_work_t* req) {
550551
delete baton;
551552
}
552553

554+
Handle<Value> Database::Wait(const Arguments& args) {
555+
HandleScope scope;
556+
Database* db = ObjectWrap::Unwrap<Database>(args.This());
557+
558+
OPTIONAL_ARGUMENT_FUNCTION(0, callback);
559+
560+
Baton* baton = new Baton(db, callback);
561+
db->Schedule(Work_Wait, baton, true);
562+
563+
return args.This();
564+
}
565+
566+
void Database::Work_Wait(Baton* baton) {
567+
HandleScope scope;
568+
569+
assert(baton->db->locked);
570+
assert(baton->db->open);
571+
assert(baton->db->handle);
572+
assert(baton->db->pending == 0);
573+
574+
if (!baton->callback.IsEmpty() && baton->callback->IsFunction()) {
575+
Local<Value> argv[] = { Local<Value>::New(Null()) };
576+
TRY_CATCH_CALL(baton->db->handle_, baton->callback, 1, argv);
577+
}
578+
579+
baton->db->Process();
580+
581+
delete baton;
582+
}
583+
553584
Handle<Value> Database::LoadExtension(const Arguments& args) {
554585
HandleScope scope;
555586
Database* db = ObjectWrap::Unwrap<Database>(args.This());
Collapse file

‎src/database.h‎

Copy file name to clipboardExpand all lines: src/database.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ class Database : public ObjectWrap {
131131
static void Work_Exec(uv_work_t* req);
132132
static void Work_AfterExec(uv_work_t* req);
133133

134+
static Handle<Value> Wait(const Arguments& args);
135+
static void Work_Wait(Baton* baton);
136+
134137
static Handle<Value> Close(const Arguments& args);
135138
static void Work_BeginClose(Baton* baton);
136139
static void Work_Close(uv_work_t* req);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.