Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.

Commit 64ff8f6

Browse files
author
Lars-Magnus Skog
committed
Add TODO for db_close() (when open iterators)
1 parent f7c6d93 commit 64ff8f6

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

binding.cc

+41-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,47 @@ NAPI_METHOD(db_close) {
498498

499499
napi_value callback = argv[1];
500500
CloseWorker* worker = new CloseWorker(env, database, callback);
501-
worker->Queue();
501+
502+
if (database->iterators_.empty()) {
503+
worker->Queue();
504+
NAPI_RETURN_UNDEFINED();
505+
}
506+
507+
// TODO fix me!
508+
509+
/*
510+
// yikes, we still have iterators open! naughty naughty.
511+
// we have to queue up a CloseWorker and manually close each of them.
512+
// the CloseWorker will be invoked once they are all cleaned up
513+
database->pendingCloseWorker = worker;
514+
515+
for (
516+
std::map< uint32_t, leveldown::Iterator * >::iterator it
517+
= database->iterators.begin()
518+
; it != database->iterators.end()
519+
; ++it) {
520+
521+
// for each iterator still open, first check if it's already in
522+
// the process of ending (ended==true means an async End() is
523+
// in progress), if not, then we call End() with an empty callback
524+
// function and wait for it to hit ReleaseIterator() where our
525+
// CloseWorker will be invoked
526+
527+
leveldown::Iterator *iterator = it->second;
528+
529+
if (!iterator->ended) {
530+
v8::Local<v8::Function> end =
531+
v8::Local<v8::Function>::Cast(iterator->handle()->Get(
532+
Nan::New<v8::String>("end").ToLocalChecked()));
533+
v8::Local<v8::Value> argv[] = {
534+
Nan::New<v8::FunctionTemplate>(EmptyMethod)->GetFunction() // empty callback
535+
};
536+
Nan::AsyncResource ar("leveldown:iterator.end");
537+
ar.runInAsyncScope(iterator->handle(), end, 1, argv);
538+
}
539+
}
540+
541+
*/
502542

503543
NAPI_RETURN_UNDEFINED();
504544
}

0 commit comments

Comments
 (0)